0%

一台电脑部署多个hexo博客ssh密钥管理

本文介绍一台电脑上部署多个hexo博客后,github的ssh密钥管理冲突问题,方便多个hexo环境直接使用ssh进行push。如果配置错误,将导致一个仓push不上去的问题。

1. 生成多个ssh密钥

使用ssh-keygen -t rsa生成密钥,其中-t后面表示类型,按下enter后会让选择密钥文件名字。注意两次生成命名不要一样,第一次默认第二次差异化一下。

2.github配置

此步略过,正常给两个仓库配置不同ssh密钥即可。

3.修改本机/Users/yanzi/.ssh/config文件

1
2
3
4
5
6
7
8
9
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

Host github-yanzi1225627
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github

注意第二个密钥对应的账号host后面跟上用户名,其中的IdentityFile指定到对应密钥文件。

4.hexo仓库配置_config.yml

第一个hexo正常配置即可:

1
2
3
4
5
6
deploy:
type: git
repository:
github: git@github.com:youraccount/youraccount.github.io.git

branch: master

第二个hexo博客:

1
2
3
4
5
deploy:
type: git
repository:
github: git@github-youraccount:youraccount/youraccount.github.io.git
branch: master

注意其中的git@github-youraccount:必须带上自己的用户名,和ssh密钥目录的config配置保持一致。

参考