loading...
Cover image for How to use a SSH key for GitHub on unix based systems (Linux or Mac)

How to use a SSH key for GitHub on unix based systems (Linux or Mac)

eddyvinck profile image Eddy Vinck ・1 min read

Navigate to ~/.ssh

ssh-keygen -t rsa -b 4096 -C "your@email.com"

When asked to give your key a name I recommend naming it after the service you are using it for, so for me this will be github.

Create ~/.ssh/config with the following content

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github

Add the contents of the public key file (~/.ssh/github.pub) to your GitHub account https://github.com/settings/keys

Done! Now you don't have to specify which SSH key you want to use when using SSH to interface with GitHub.

connecting with SSH without specifying which key to use

This is how I do it.

Bonus: If you use multiple accounts you can do this in your config:

# account myfirstaccount (username)
Host github.com-myfirstaccount
  HostName github.com
  User git
  IdentityFile ~/.ssh/github-myfirstaccount

# account mysecondaccount
Host github.com-mysecondaccount
  HostName github.com
  User git
  IdentityFile ~/.ssh/github-mysecondaccount

Posted on by:

eddyvinck profile

Eddy Vinck

@eddyvinck

Developer who tweets too much

Discussion

markdown guide