Git如何生成多个ssh key添加到ssh-agent管理项目

生成新的ssh密钥

ssh-keygen -t rsa -b 4096 -C "[email protected]"

不要一直回车键,输入新的名称 id_rsa_new

Enter a file in which to save the key (/Users/you/.ssh/id_rsa):id_rsa_new

启动ssh-agent

$ eval "$(ssh-agent -s)"
> Agent pid 59566

将SSH私钥添加到ssh-agent并将密码存储在密钥链中

ssh-add ~/.ssh/id_rsa_new

需要修改~/.ssh/config文件以自动将密钥加载到ssh-agent中并在密钥链中存储密码

Host new
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_new
  User test

Host old
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa
  User test

回到GitHub账号添加秘钥不再复述
请看link

ssh -T git@new
测试链接,如下继续连接 yes

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
 > RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
 > Are you sure you want to continue connecting (yes/no)?

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
  > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  > Are you sure you want to continue connecting (yes/no)?

如下,出现successfully表示成功

> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

添加仓库地址 Host 对应config中的配置
git remote add origin git@:xxxx/test.git

这样就可以实现管理多个GitHub项目
win系统配置过程会出现更多问题,再叙。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章