执行ssh-add时添加私钥到git中报错Could not open a connection to your authentication agent

执行ssh-add ~/.ssh/rsa命令添加本地私钥到git时,

报标题上的错误


报错信息如下:

SSH private-keys are usually stored encrypted on the computers they are stored on. A pass-phrase is used to decrypt them when they are to be used. Since most people use SSH public-private key-pairs to get around typing in passwords all the time, the ssh-agentdaemon exists to store decrypted private-keys you plan on using in a given session. The thing most people get tripped up on when using ssh-agent is that what the program outputs, some borne or csh shell commands, needs to be run. It may look like ssh-agent has set some variables for you, but it has in fact done no such thing. If you call ssh-add without processing ssh-agent’s output, it will complain it is unable to open a connection to your authentication agent. The most straightforward way to run ssh-agent on the command line is as follows: eval `ssh-agent`. After doing this, calls to ssh-add should succeed without error.


解决方案:

先执行  

eval `ssh-agent`
再执行
ssh-add ~/.ssh/rsa

成功

ssh-add -l 

就有新加的rsa了


若途中报错 “Permissions ???? for '/Users/xxx/.ssh/rsa' are too open”的问题,则是该私钥文件权限过高,需要设置其权限:

chmod 600 ~/.ssh/rsa

你可能感兴趣的:(编程经验)