Git permission denied (public key) error
Have you tried creating a new SSH certificate, i.e. key pair?
1 Generate default key pair:
$ ssh-keygen -t rsa -C "[email protected]"
Don't use this if you already have an SSH certificate.
2 Generate additional key pairs:
$ ssh-keygen -t rsa -C "[email protected]"
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