多站点使用不同的ssh key
默认ssh登录时使用的是id_rsa文件,我们也可以指定其他文件;
首先我们生成不同的key:
ssh-keygen -t rsa -C "user1" -f user1 ssh-keygen -t rsa -C "user2" -f user2
|
我们生成user1,user2两个不同的ssh key,然后我们在.ssh下创建config文件,
输入:
Host company HostName company.com User git IdentityFile ~/.ssh/user1 Host github HostName github.com User git IdentityFile ~/.ssh/user2
|
这样访问company.com就会使用user1, 访问github.com就会使用user2
同一站点使用不同的ssh key
我们有时候需要在同一站点使用不同的ssh key, 比如使用gitcafe的pages服务,
想要创建两个站点,但是gitcafe上不允许不同的用户使用同一个ssh key,
我们在config文件里做相应的修改
Host gitcafe-site1 HostName gitcafe.com User git IdentityFile ~/.ssh/user1 Host gitcafe-site2 HostName gitcafe.com User git IdentityFile ~/.ssh/user2
|
然后我们更改git参考的远程地址
#site1 $ git remote remove origin $ git remote add origin git@gitcafe-site1:user1/user1.git #site2 $ git remote remove origin $ git remote add origin git@gitcafe-site2:user2/user2.git
|
关键是把gitcafe.com改为gitcafe-site1和gitcafe-site2
如果使用hexo, 在hexo的config文件中,把deploy的远程地址改成gitcafe-site1这样的形式即可
deploy:
type: git
repo: git@gitcafe-site1:user1/user1.git
#
评论列表