A couple of days ago I was working OK and committing stuff to GitHub without any issues.
Yesterday I started to receive this on "git push":
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
1) I have the ssh keys and checked on my GitHub account, the fingerprint matches (ssh-keygen -lf github_rsa.pub).
2) Tried to generate a new key, just in case,it is "github2_rsa", added the public key to GitHub from the web, and changed my ssh config. Changed the IdentityFile to use github2_rsa instead of github_rsa, and added the User=git (a solution recommended to add it)
Host github.com
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
User=git
IdentityFile=~/.ssh/github2_rsa
3) Trying to push again, got the same error.
4) ssh -vT git@github.com
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Applying options for github.com
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: identity file /.ssh/github2_rsa type -1
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-sha1 none
debug1: kex: client->server aes128-cbc hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/github2_rsa
debug1: No more authentication methods to try.
Permission denied (publickey).
My environment is an old virtual machine with WinXP (yes I know, is for a specific env that a project needs), and was using SmartGit to commit, then I tried from the command line when it started to fail, but got the same issue.
Already tried many solutions on StackOverflow and didn't work.
For instance:
Some solutions say "ssh-add xxx" running ssh-add I get:
Could not open a connection to your authentication agent.
Others say to use: eval "$(ssh-agent -s)" but in windows eval is not recognized as a command.
I ran into this issue today on Big Sur where I was suddenly getting git@github.com: Permission denied (publickey)
when pushing to GitHub. Reboot didn't help. Ran into this answer which fixed it for me: https://apple.stackexchange.com/questions/254468/macos-sierra-doesn-t-seem-to-remember-ssh-keys-between-reboots.
In short, the problem was that the ssh agent had lost my ssh keys. Running ssh-add -A
worked (until next reboot?) but a better solution was to add the following to my ~/.ssh/config
:
Host *
AddKeysToAgent yes
UseKeychain yes