SSH – Load key “/Users/username/.ssh/id_rsa.pub”: invalid format
Suddenly the git push
via SSH failed, and the remote server returned something like invalid format for the public key id_rsa.pub
?
Terminal
git push
Load key "/Users/username/.ssh/id_rsa.pub": invalid format
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Last week, everything still working fine, unsure what is the root cause of it?
1. Check ~/.ssh/config
Review the ~/.ssh/config
file and ensure the IdentityFile
points to the private key id_rsa
, not the public key id_rsa.pub
. The common mistake is put the public key id_rsa.pub
as the IdentityFile
value.
Terminal
cat ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa.pub
Note
For the ~/.ssh/config
, the IdentityFile
should point to the private key that the SSH client uses to connect to the remote server (The remote server should have the public key id_rsa.pub`).
2. Solution
Open the ~/.ssh/config
file, update the IdentityFile
, and ensure it points it to the private key id_rsa
.
Terminal
nano ~/.ssh/config
~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Thank You !