0%

Debian安装Hexo环境并托管Github

设置GitHub免密登录

  1. 安装Git

    sudo apt install git -y

  2. 配置Git

    git config --global user.name <你的名称>
    git config --global user.email <你的邮箱>

  3. Git生成密钥,输入以下命令,之后连续按3次回车:

    ssh-keygen -t rsa -C <你的邮箱>

  4. 打印生成的公钥,将输出复制下来:

    cat ~/.ssh/id_rsa.pub

  5. 将复制后的公钥添加到GitHub中:点击页面右上角头像——Setting——SSH And GPG keys——New SSH Keys,填写后添加即可。

  6. 运行如下命令,输入yes添加服务器,未报错则完成免密设置。

    ssh -T git@github.com

安装Hexo

运行如下命令,运行前请确保能够访问raw.githubusercontent.com,详见我之前写的解决raw.githubusercontent.com无法访问的问题

1
2
3
4
5
6
7
sudo apt install curl -y
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
export NVM_NPM_ORG_MIRROR=https://npmmirror.com/mirrors/npm/
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/
nvm install stable
npm config set registry https://registry.npmmirror.com
npm install hexo-cli -g

设置GitHub托管

  1. 创建新的博客目录

    hexo init .

  2. 在GitHub新建仓库,并复制下该仓库的Git URL。

  3. 修改博客根目录下的_config.yml

    将其中的deploy部分修改改为如下格式:

    1
    2
    3
    4
    deploy:
    type: git
    repo: <目标仓库Git URL>
    branch: main