0%

hexo deploy配置免输入github账号密码

每次hexo d都要输入密码太烦了

生成ssh密钥对

Linux系统:

1
2
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

Windows可以使用Xshell生成秘钥对, 之后导入到 C:\Users\Username\.ssh目录下

公钥命名为id_rsa.pub, 私钥命名为id_rsa

github添加ssh公钥

方法一: 在个人profile里添加公钥

Your profile -> SSH and GPG keys -> New SSH key -> 复制生成的公钥 ->

方法二: 项目的设置里面添加

Settings -> Deploy keys -> Add Deploy key -> 复制公钥 -> 勾选Allow write access -> Add new

设置远程git地址:

1
2
3
4
5
6
7
8
cd blog/.deploy_git
git remote rm origin
git remote set-url origin git@github.com:lovehhf/lovehhf.github.io.git


git remote -v # 查看当前传输协议
origin git@github.com:lovehhf/lovehhf.github.io.git (fetch)
origin git@github.com:lovehhf/lovehhf.github.io.git (push)

编辑配置文件_config.yml, 将deployhttps协议改为使用git协议:

vim _config.yml

1
2
3
4
deploy:
type: git
repository: git@github.com:lovehhf/lovehhf.github.io.git
branch: master

部署到github: hexo d -g