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

简介: 生成新的ssh密钥 ssh-keygen -t rsa -b 4096 -C "your@example.com" 不要一直回车键,输入新的名称 id_rsa_new Enter a file in which to save the key (/Users/you/.

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

ssh-keygen -t rsa -b 4096 -C "your@example.com"

不要一直回车键,输入新的名称 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/config文件以自动将密钥加载到ssh-agent中并在密钥链中存储密码
Mac系统如下

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

Win系统如下

Host new
HostName github.com
IdentityFile C:\\Users\Eric\.ssh\id_rsa_new
PreferredAuthentications publickey
User Eric

Host old
HostName github.com
IdentityFile C:\\Users\Eric\.ssh\id_rsa
PreferredAuthentications publickey
User Eric

将SSH私钥添加到ssh-agent并将密码存储在密钥链中
Mac系统如下

ssh-add ~/.ssh/id_rsa_new

Win系统如下

ssh-add C:\\Users\Eric\.ssh\id_rsa_new

Win系统 ssh-add 可能出现报错看这里解决

回到GitHub账号
添加ssh key看这里

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@github.com:xxxx/test.git

这样就可以实现管理多个GitHub项目,多看官方文档,结合官方文档解决问题更高效
Win系统可能出现很多问题,Mac有时候更好用呢,熬了两个晚上把Mac和Win系统问题解决分享出来,用你那高冷的方式点个赞吧
附官方文档
Git
GitHub
_3ACF5CB7_3CDF_4F2C_FF45_D428BEDFB7F6_

目录
相关文章
|
2月前
|
存储 网络安全
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
611 1
|
8月前
|
安全 网络安全
jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 如何处理
【5月更文挑战第24天】jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 如何处理
748 1
|
8月前
|
算法 网络安全
Unable to negotiate with 127.0.0.1 port 29215: no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 解决
【5月更文挑战第5天】Unable to negotiate with 127.0.0.1 port 29215: no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 解决
452 7
|
8月前
|
弹性计算 运维 Shell
基于key验证多主机ssh访问
【4月更文挑战第30天】
89 1
|
8月前
|
安全 网络安全
jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha>问题处理方法
【5月更文挑战第10天】jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha>问题处理方法
381 0
|
8月前
|
算法 网络安全
no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 问题解决
【5月更文挑战第8天】no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 问题解决
2021 0
|
8月前
|
缓存 网络安全 开发工具
Git服务器报错:host key for (ip地址) has changed and you have requested strict checking
Git服务器报错:host key for (ip地址) has changed and you have requested strict checking
549 0
|
8月前
|
网络安全 数据安全/隐私保护
如何使用ssh key免密码登录服务器?
如何使用ssh key免密码登录服务器?
|
安全 Shell 网络安全
SSH key -本地与远程中央仓库连接认证
SSH key -本地与远程中央仓库连接认证
SSH key -本地与远程中央仓库连接认证
|
网络安全 数据安全/隐私保护 Linux