突然间,通过SSH的git push 失败了,远程服务器返回的信息是:公钥的格式无效id_rsa.pub?
终端
git push
Load key "/Users/username/.ssh/id_rsa.pub": invalid format
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
上周,一切都还正常,不知道是什么原因造成的?
1.检查~/.ssh/config
查看~/.ssh/config 文件,确保IdentityFile 指向私钥id_rsa ,而不是公钥id_rsa.pub 。常见的错误是把公钥id_rsa.pub 作为IdentityFile 的值。
终端
cat ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa.pub
注意
对于~/.ssh/config ,IdentityFile 应该指向 SSH 客户端用来连接到远程服务器的私钥(远程服务器应该有公钥 id_rsa.pub`)。
2.解决方案
打开~/.ssh/config 文件,更新IdentityFile ,并确保它指向私钥id_rsa 。
终端
nano ~/.ssh/config
~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa