SSH keys let you authenticate with GitHub without typing a password every time. You generate a key pair: a private key (stays on your machine) and a public key (added to GitHub). Git then uses the private key to prove your identity when pushing or pulling.
Git
Beginner
8 min read
SSH Keys Setup for GitHub
Example
# Step 1: Generate an ED25519 SSH key pair (recommended):
ssh-keygen -t ed25519 -C "jane@example.com"
# Accept the default file location (~/.ssh/id_ed25519)
# Set a passphrase for extra security (optional but recommended)
# Step 2: Start the SSH agent and add your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Step 3: Copy your PUBLIC key:
cat ~/.ssh/id_ed25519.pub
# Output looks like:
# ssh-ed25519 AAAAC3Nza... jane@example.com
# Step 4: Add the public key to GitHub:
# GitHub -> Settings -> SSH and GPG keys -> New SSH key
# Paste the public key content
# Step 5: Test the connection:
ssh -T git@github.com
# Hi jane! You've successfully authenticated.
# Step 6: Clone via SSH (not HTTPS):
git clone git@github.com:jane/my-repo.git
# Change an existing repo from HTTPS to SSH:
git remote set-url origin git@github.com:jane/my-repo.git