在一个新的Linux环境下使用之前在其他机器上已经生成的id_rsa和id_rsa.pub文件连github报错:
The authenticity of host 'github.com (20.205.243.166)' can't be established.
...
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
sign_and_send_pubkey: signing failed for RSA "/home/g/.ssh/id_rsa" from agent: agent refused operation
git@github.com: Permission denied (publickey).
fatal: 无法读取远程仓库。
使用的id_rsa和id_rsa.pub本来是可以用来正常访问github的,在github上个人的账号里也设置了对应的key,怎么在新机器环境下就不行了呢?查看网上别人说的解决办法,出这种错误后,一般人都是重新创建公私钥配置了一遍,这不是我想要的解决办法,但又不知道为何不让访问,感觉上面的Permission denied错误提示说的不明不白的。
无意中随便试着执行了一下:
ssh-add ~/.ssh/id_rsa
发现报的错给出了准确的原因:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0775 for '/home/g/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
原来是文件的权限太多了,执行一下chmod 100 /home/g/.ssh/id_rsa只授予read权限,然后再执行
ssh-add ~/.ssh/id_rsa
就不报错了,然后用git clone git@github.com:/...方式下载代码都正常了
记录一下以防忘记后面再遇到浪费时间去查这个问题。