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

Use Cases

  1. Same service (e.g. GitHub) different account (personal vs work email account)
  2. Same account (e.g. personal email) different service (GitHub vs BitBucket)
  3. Same service and account, different client/device (e.g. Mac, Phone, Tablet or setting up new machine)
  4. ??

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 

Reference