windows下git配置github和gitee SSH-Key密钥方便同时将本地分支推送到远程仓库
2021/6/14 7:23:31
本文主要是介绍windows下git配置github和gitee SSH-Key密钥方便同时将本地分支推送到远程仓库,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
windows下 git配置github和gitee SSH-Key密钥方便同时将本地分支推送到远程仓库
1先配置giteee的SSH-Key
生成一个gitee用的SSH-Key密钥:输入命令:(gitee_id_rsa是生成公钥的名)
$ ssh-keygen -t rsa -C '你的邮箱' -f ~/.ssh/gitee_id_rsa
点击三次回车,这里什么也不用填。
2.配置github的SSH-Key
生成一个github用的SSH-Key密钥:输入命令:(github_id_rsa是生成公钥的名)
$ ssh-keygen -t rsa -b 4096 -C "你的邮箱" -f ~/.ssh/github_id_rsa
点击三次回车,这里什么也不用填。
2.1 将SSH密钥添加到 ssh-agent,输入命令
$ eval $(ssh-agent -s)
返回类似这样的东西
> Agent pid 595
2.2将ssh密钥添加到github
$ ssh-add ~/.ssh/github_id_rsa
3:在C:\Users\你的用户名.ssh目录下可以看见升级的密钥文件,并新建一个config文件,添加如下内容
# gitee 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密钥添加到gitee
ssh-add ~/.ssh/gitee_id_rsa
在任何页面的右上角,单击您的个人资料照片->设置->左侧菜单栏找到SSH公钥->将C:\Users\你的用户名.ssh目录下gitee_id_rsa.pub文件打开复制里面的内容添加到密钥(有可能输入密码,输入就行)。
5.ssh密钥添加到github
在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)。
在用户设置侧边栏中,单击 SSH and GPG keys(SSH 和 GPG 密钥)。
单击 New SSH key(新 SSH 密钥)。
在 “Title”(标题)字段中,为新密钥添加描述性标签。 将C:\Users\你的用户名.ssh目录下github_id_rsa.pub文件打开复制里面的内容添加到密钥粘贴到 “Key”(密钥)字段。
单击 Add SSH key(添加 SSH 密钥)。
如有提示,请确认您的 GitHub 密码。
6.用ssh命令分别测试
6.1 测试gitee
输入以下内容:
$ ssh -T [git@gitee.com](mailto:git@gitee.com)
若返回 Hi XXX! You’ve successfully authenticated, but 码云 Gitee — 基于 Git 的代码托管和研发协作平台 does not provide shell access. 内容,则证明添加成功。
6.2 测试github
输入以下内容:
$ ssh -T [git@github.com](mailto:git@github.com)
您可能会看到类似如下的警告:
> The authenticity of host ‘Build software better, together (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 ‘Build software better, together (IP ADDRESS)’ can’t be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
验证您看到的消息中的消息之一,然后输入 yes:提示这个表示配置成功
> Hi username! You’ve successfully authenticated, but GitHub does not
> provide shell access.
7.本博文已经同步到个人博客,如有需要请移步:
http://moyisuiying.com/index.php/git%e5%ad%a6%e4%b9%a0/455.html
这篇关于windows下git配置github和gitee SSH-Key密钥方便同时将本地分支推送到远程仓库的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-20接口模块封装入门教程
- 2024-09-20请求动作封装入门教程
- 2024-09-20登录鉴权学习:新手入门教程
- 2024-09-20后台管理开发学习:新手入门指南
- 2024-09-20后台管理系统开发学习:从入门到实践
- 2024-09-20后台开发学习:从入门到初级实战指南
- 2024-09-20后台综合解决方案学习:从入门到实践
- 2024-09-20接口模块封装学习入门指南
- 2024-09-20请求动作封装学习:新手入门教程
- 2024-09-20登录鉴权入门:打造安全的用户认证系统