本文转载自:错误:ssh-add -K ~/.ssh/id_rsa Could not open a connection to your authentication agent.

解决方法:

第一步:检查已有的SSH keys

$ ls -al ~/.ssh

第二步:生成新的SSH key

$ ssh-keygen -t rsa -C "youremail@example.com"

然后将这个新的key添加到ssh-agent中:

$ ssh-agent -s
$ ssh-add ~/.ssh/id_rsa

如果ssh-add出错,执行ssh-agent bash,再次回到ssh-add命令。

第三步:将SSH key添加到你的GitHub账户

github的账户页的右上角,点击Setting—>SSH keys—>Add SSH key,在title栏输入一个自己喜欢的标题,key栏中粘贴id_rsa.pub的公钥内容,最后点击Add key按钮。
第四步:检查SSH key是否成功设置

$ ssh -T git@github.com

如果得到下面的结果,说明你的设置是成功的!
Hi username! You’ve successfully authenticated, but GitHub does not

参考:
(诊断)为GitHub添加SSH key时出现“Could not open a connection to your authentication agent”错误的应对方案。
执行ssh-add时出现Could not open a connection to your authentication agent

Logo

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

更多推荐