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

 2023-09-13 阅读 11 评论 0

摘要: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 git如何生成ss

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

git如何生成ssh密钥?启动ssh-agent

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

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

Host newHostName github.comAddKeysToAgent yesUseKeychain yesIdentityFile ~/.ssh/id_rsa_newUser testHost oldHostName github.comAddKeysToAgent yesUseKeychain yesIdentityFile ~/.ssh/id_rsaUser test

Win系统如下

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

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

ssh-add ~/.ssh/id_rsa_new

Win系统如下

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

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

ssh server。回到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)?

git如何生成密钥,如下,出现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系统可能出现很多问题,Mac有时候更好用呢,熬了两个晚上把Mac和Win系统问题解决分享出来,用你那高冷的方式点个赞吧
附官方文档
Git
GitHub
_3ACF5CB7_3CDF_4F2C_FF45_D428BEDFB7F6_

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/53672.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息