GitHub: Authenticated Access via SSH

This article describes how to set up authenticated access to a (private or public) GitHub repository from Linux.

Create & Set Up an SSH Key

SSH Key Creation

Create a new SSH key:

# 1. Adjust the email
# 2. Set a strong passphrase when asked
ssh-keygen -t ed25519 -C "you@example.com"

Rename the new key to whatever descriptive name you favor (I’m simply using github):

mv ~/.ssh/id_ed25519 ~/.ssh/github
mv ~/.ssh/id_ed25519.pub ~/.ssh/github.pub

SSH Key Setup: Local

Specify that the new key is to be used for github.com by adding the following to ~/.ssh/config:

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

SSH Key Setup: GitHub

Add the public key to your GitHub account at Settings > SSH and GPG keys > New SSH key.

Enable Automatic Authentication

Start an SSH agent for your terminal session and add the key to be used. Supply the key’s passphrase when asked:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github

With the above in place, the git command won’t ask you for the passphrase to you private SSH key anymore - in the current terminal session.

Test Authentication

ssh -T git@github.com -v

More verbose output:

ssh -vvT git@github.com -v

Repo: Check Out via SSH (not HTTPS)

If the repository was checked out via HTTPS, switch to SSH:

git remote set-url origin "$(git remote get-url origin | sed -E 's#https://github.com/(.+)#git@github.com:\1#')"

Comments

Related Posts

Latest Posts

Beautiful Slide Decks from Markdown: Presenting with Slidev

Beautiful Slide Decks from Markdown: Presenting with Slidev
Would you like to get away from PowerPoint and author slide decks in Markdown? Then Slidev may be just what you’re looking for. It’s a web app for presentations. The fact that it’s geared towards developers shouldn’t put you off. After all, who isn’t a developer these days, with AI? Slidev comes with the beautiful Tahta themes and supports features like syntax highlighting and animations. Export options to PDF and PPTX allow for easy sharing. This article shows how to get started.
Applications