++

实现多个SSH将Hexo部署到GitHub

2017-10-07

Bash
1
2
#生成第一个SSH key
$ ssh-keygen -t rsa -C "E-mail 1"
Bash
1
2
#生成第二个SSH key并命名为id_rsa_life
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_life -C "E-mail 2"

此时~/.ssh/目录共有4个文件:id_rsaid_rsa.pubid_rsa_lifeid_rsa_life.pub

Bash
1
2
3
#创建config文件并设置权限
touch ~/.ssh/config
chmod 600 ~/.ssh/config

编辑config添加以下内容并保存

1
2
3
4
5
6
7
8
Host github.com  
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host github_life.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_life

测试配置是否正确

Bash
1
2
$ ssh -T git@github.com
$ ssh -T git@life.github.com

若提示“Hi xxx! You’ve successfully authenticated.”则成功

站点1配置文件按HTTPS即可,修改站点2配置文件以SSH格式

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

由此已实现两个Hexo blog同时部署至GitHub,三个及以上同理

Tags: 学习