Use a Specific SSH Key for a Github Repository

Include this block in your ~/.ssh/config file:

Host *.github.com github.com
    Hostname github.com
    User git
    IdentityFile ~/.ssh/pub/%n.pub
    IdentitiesOnly yes

Then you can have a key ~/.ssh/example.github.com and clone from [email protected]/owner/repo and it still connects to github.com but with that specific key. Super handy if you end up with a bunch of different corporate accounts and have deployment keys and nonsense.

The %n makes it use the hostname you provided, so it looks for the relevant key.

References

Thanks Charlie at my current employer ;)



#ssh #github #authentication #workarounds