Git配置多个SSH-Key

2020-06-23  本文已影响0人  对方正在杰收

1.根据邮箱地址生成不同的rsa key

# gitee_id_rsa 保证名字唯一
$ ssh-keygen -t rsa -C 'xxxxx@company.com' -f ~/.ssh/gitee_id_rsa

2.在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

$ touch config

3.编辑内容 $vi config

Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

4.用ssh命令测试

$ ssh -T git@gitee.com

5.复制key

$ pbcopy < ~/.ssh/gitee_id_rsa.pub
上一篇 下一篇

猜你喜欢

热点阅读