Ssh Key Pair Issue
SSH KeyPair Issues
Problem
Permission denied when accessing GitHub repos via git CLI
Debugging
ssh -v -i ~/.ssh/mykey user@host
ssh -T -v git@github.com
Solution
- Check if
git remote -vmatches with host in ssh config~/.ssh/config - Check if non default
~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519, ~/.ssh/id_ed25519_sk and ~/.ssh/id_rsaidentify file added to ssh config or not - If not, update
.git/config
Use Cases
- Same service (e.g. GitHub) different account (personal vs work email account)
- Same account (e.g. personal email) different service (GitHub vs BitBucket)
- Same service and account, different client/device (e.g. Mac, Phone, Tablet or setting up new machine)
- ??
Opinion:
General rule of thumb: 1 keypair per device per account https://serverfault.com/questions/13354/best-system-for-managing-ssh-keys/23818#23818 (opens in a new tab)
E.g.
# ~/.ssh/
id_ed25519
id_ed25519.pub
id_ed25519_dev
id_ed25519_dev.pub
# ~/.ssh/config
Host *
AddKeysToAgent yes # auto adds key to ssh agent
UseKeychain yes
Host github.com
IdentityFile ~/.ssh/id_ed25519
Host github_dev.com
IdentityFile ~/.ssh/id_ed25519_dev
IdentitiesOnly yes