GitHub SSH Setup Using OpenSSH (Linux / Raspberry Pi)

This walkthrough shows how to configure OpenSSH so you can access GitHub using SSH (git clone, git pull, git push) without passwords or tokens.


1. Install required packages

sudo apt update
sudo apt install -y git openssh-client

2. Create the SSH directory

mkdir -p ~/.ssh
chmod 700 ~/.ssh

3. Generate an SSH key for GitHub (ed25519)

ssh-keygen -t ed25519 -C "enkiel@rpi-github" -f ~/.ssh/id_ed25519
  • Press Enter to accept the default location
  • Passphrase is optional but recommended

This creates:

  • ~/.ssh/id_ed25519 (private key)
  • ~/.ssh/id_ed25519.pub (public key)

4. Start ssh-agent and load the key

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

Verify:

ssh-add -l

5. Add the public key to GitHub

cat ~/.ssh/id_ed25519.pub

Copy the full output.

On GitHub:

  1. Go to Settings → SSH and GPG keys
  2. Click New SSH key
  3. Title: rpi
  4. Paste the key
  5. Save

6. Configure SSH for GitHub

Create the SSH config file:

nano ~/.ssh/config

Add:

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

Set permissions:

chmod 600 ~/.ssh/config

7. Test GitHub SSH access

Expected output:

Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

8. Use GitHub via SSH

Clone a repository

git clone [email protected]:USER/REPO.git

Convert an existing HTTPS repo to SSH

cd repo
git remote set-url origin [email protected]:USER/REPO.git
git pull

9. Auto-load SSH key on login (optional)

Add to ~/.bashrc:

eval "$(ssh-agent -s)" >/dev/null
ssh-add ~/.ssh/id_ed25519 2>/dev/null

Reload:

source ~/.bashrc

Troubleshooting

Permission denied (publickey)

  • Ensure key is loaded: ssh-add -l
  • Ensure key is added to GitHub
  • Check SSH config: cat ~/.ssh/config

Fix permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/config

Done. This system is now configured for GitHub SSH access using OpenSSH.