1.打开终端(在Windows上可使用Git Bash)。

2.生成SSH密钥对(邮箱为你自己的邮箱地址):

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

按提示操作,可以选择设置密码保护密钥,也可以直接回车接受默认设置

3.确认SSH密钥已生成:

ls -al ~/.ssh

你应该看到id_rsa(私钥)和id_rsa.pub(公钥)。

4.添加SSH密钥到ssh-agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

5.获取你创建的公钥内容并将公钥内容复制并添加到Git服务器的SSH密钥部分。

6.测试SSH连接:

ssh -T git@github.com

我在测试连接时出现了报错

但是不影响我拉取代码,也可以拉取成功

但是如果拉取时出现这个报错:

Unable to negotiate with 10.38.18.251 port 29418: no matching host key type found. Their offer: ssh-rsa,ssh-dss
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

那么解决方案在:

https://blog.csdn.net/weixin_44690195/article/details/127003744

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐