2

I've been using ssh keys with github for a while now. Suddenly i can't push and I'm getting a Permission denied (publickey) error. Here's what I've tried so far:

  • Checked the ssh key is in the correct directory (~/.ssh)
  • Tried reuploading my public key to github (I get a message that the key already exists)
  • Double checked that the output of ssh-add -l -E sha256 on my system agrees with the string in my ssh settings on my github account
  • Followed all the steps in the "Troubleshooting ssh" section of the github docs. (Everything seems gucci)
  • Banged my head against the wall for an hour

So far nothing has helped. This is my last resort. I'll greatly appreciate any and all suggestions. Here's the output of my ssh -vT [email protected]

OpenSSH_7.2p2 Ubuntu-4ubuntu2.10, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/MY_USER_NAME/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [140.82.114.3] port 22.
debug1: Connection established.
debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
debug1: Remote protocol version 2.0, remote software version babeld-fb957b4d
debug1: no match: babeld-fb957b4d
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/MY_USER_NAME/.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/MY_USER_NAME/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_dsa
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_ecdsa
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).


Update: I'm having the same problem with a different github account that has a different set of keys. Same computer.

6
  • Hope this link will help you to overcome this issue. stackoverflow.com/questions/9960897/… Commented Dec 10, 2021 at 4:28
  • 2
    SSH is telling you that it couldn't find the public key corresponding to id_rsa: debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory. Also, the ssh server isn't responding with "authentication success" after being offered the id_rsa key. Are you absolutely, positively, 100% sure that you uploaded the correct corresponding public key to github? Commented Dec 10, 2021 at 7:39
  • 1
    As @kalatabe said: debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1 means ssh found .ssh/id_rsa. But debug1: key_load_public: No such file or directory means ssh didn't find .ssh/id_rsa.pub - the public key that would go with this private key. It's not clear why it didn't find it, since ssh-keygen generates them in pairs, but I'd suspect something is going wrong with the agent setup. Commented Dec 10, 2021 at 8:06
  • 1
    @kalatabe The "key_load_public" error refers to the next key in the list, not the previous key. ssh found id_rsa, but not id_rsa-cert etc. Commented Dec 10, 2021 at 14:03
  • @kalatabe I double checked and the public key is there. Also, I'm a bit of a newbie, so please correct me if I'm wrong, but I was under the impression that you don't need the public key to authenticate. As long as your server has the public key (which github does), it's the private key that authenticates. Commented Dec 10, 2021 at 15:28

5 Answers 5

2

So, I eventually figured it out. Turns out my computer just didn't like the fact that I had multiple ssh keys (possibly because one of them was password protected and others weren't?) Moving all but one of the ssh keys out from the ~/.ssh directory and restarting the computer solved my problem. I previously have tried removing all but one of the ssh keys but apparently a reboot was also needed.

Sign up to request clarification or add additional context in comments.

Comments

2

Note that if you have an old DSA key, you'll see "Server accepts key:", but will still ultimately fail. GH is phasing out DSA keys, so it may have been 'accepted', but not allowed to proceed.

Comments

1

My answer might not help or sound silly. But in my situation, I'm just deleting the know_hosts file and pull/push again, then everything works as expected.

1 Comment

Deleting known_hosts is a potential security risk and should be avoided at all costs unless you're completely aware of the implications. Also, the log includes Host 'github.com' is known and matches the RSA host key. so a changed host key wouldn't be the issue here, and manipulating known_hosts is unlikely to help.
0

One possible root cause is the Host or HostName can't intercept your target FQDN or IP address in the SSH connection. Try to modify Host or HostName to match with your target server.

Also enable debug mode for git command.

git -c core.sshCommand="ssh -vvv" clone

Comments

0

For anyone who had to generate a new ssh key because they used the wrong email like I had, here is how I fixed it:

  1. Generate new ssh key with correct email in new file.
  2. Update ~/.ssh/config with correct new file.
  3. Ensure your git profile is referencing correct email with git config --list (you should see user.email=YOUR_CORRECT_EMAIL listed)
  4. If not, update email with git config --global user.email "NEW_EMAIL" and optionally update user.name if that is not accurate.
  5. Reset all commits you had added with the wrong email with git reset HEAD~<number of commits>.
  6. Commit your changes.

You should now be good to go.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.