Git permission denied (public key) error

gitssh

I have connected many times to github and know about generating ssh keys and putting the id_rsa.pub into github settings. But for some reason with this install I can not get it to connect. I am just trying to clone a private repo to a new server but when I the clone I get :

Permission denied (publickey). fatal: The remote end hung up
unexpectedly

If I run :

ssh -T git@github.com

It tells me I have successfully authenticated.

What else can I try? I am running this on a bitnami stack so maybe that is causing issues? This is probably the problem, I just am not sure what to do about it. There are already a set of keys in the .ssh/authorized_keys dir. I left those alone as this is how I am connecting with putty/pagent. I put the new keys in /.ssh and left the authorized_keys alone. What would be the correct way to set this up? Should I just delete both pairs and start over? Use the same keys for putty and github? Why do I still authenticate if there is a problem?

Best Answer

Have you tried creating a new SSH certificate, i.e. key pair?

1 Generate default key pair:

$ ssh-keygen -t rsa -C "defaultuser@gmail.com"

Don't use this if you already have an SSH certificate.

2 Generate additional key pairs:

$ ssh-keygen -t rsa -C "seconduser@gmail.com"

3 Add non-default keys

$ ssh-add ~/.ssh/id_rsa_seconduser
Enter passphrase for /Users/defaultuser/.ssh/id_rsa_seconduser: 
Identity added: /Users/defaultuser/.ssh/id_rsa_defaultuser  (/Users/defaultuser/.ssh/id_rsa_defaultuser)

4 Set SSH configuration file (~/.ssh/config) so SSH knows which key to be used for which server:

Host github.com
  HostName github.com
  User git
  IdentityFile /Users/XXXUser/.ssh/id_rsa

Host github-client
  HostName github.com
  User git
  IdentityFile /Users/XXXUser/.ssh/id_rsa_XXXSECONDUSER

5 Make sure in the .git/config file for the Git project associated with the second user account at Github that you are using correct host name github-client but not github.com:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github-client:foobarsomeuser/foobar.git
Related Question