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

Linux Config File Version Control & Backup on GitHub

Linux Config File Version Control & Backup on GitHub
Linux famously stores all of its settings in files, making it easy to inspect, query, or backup the configuration with a plethora of tools, including Git. However, given that Git was conceived by the Linux community, there is surprisingly little integration. As a developer, I am used to managing everything with Git. Depending on my current degree of paranoia, I may put nearly or literally everything into version control. So where’s Git for Linux config files?
Software development

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware