DEV Community

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

Posted on

18 6

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

Navigate to ~/.ssh

ssh-keygen -t rsa -b 4096 -C "your@email.com"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay