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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up