HTTPS vs SSH Keys
Connect to GitHub over HTTPS with a token, or over SSH with a key pair.
GitHub offers two ways to authenticate when pushing and pulling.
HTTPS
URLs look like https://github.com/you/repo.git. You authenticate with a personal access token (not your password). Simple and works everywhere, including behind firewalls.
SSH
URLs look like [email protected]:you/repo.git. You create an SSH key pair, add the public key to GitHub, and never type credentials again.
Setting up an SSH key
- Generate a key with
ssh-keygen. - Copy the public key (
.pubfile). - Paste it into GitHub β Settings β SSH and GPG keys.
Example
# Generate a new SSH key
ssh-keygen -t ed25519 -C "[email protected]"
# Show the public key to copy into GitHub
cat ~/.ssh/id_ed25519.pub
# Test the connection
ssh -T [email protected]When to use it
- A developer generates an SSH key pair and adds the public key to GitHub so they can push without entering a password each time.
- A team member uses HTTPS with a Personal Access Token in a corporate environment where SSH is blocked by the firewall.
- A CI server uses an SSH deploy key with read-only access to clone private repos securely in automated pipelines.
More examples
Generate and register an SSH key
Creates a modern Ed25519 key pair; the public key is uploaded to GitHub so the private key authenticates pushes silently.
# Generate Ed25519 key
ssh-keygen -t ed25519 -C "[email protected]"
# Copy public key to clipboard (Linux)
cat ~/.ssh/id_ed25519.pub
# Paste into GitHub Settings > SSH and GPG keysTest SSH connection to GitHub
Confirms the SSH key is correctly registered; a successful handshake means push and pull will work without a password.
ssh -T [email protected]
# Hi username! You've successfully authenticated,
# but GitHub does not provide shell access.Switch a repo from HTTPS to SSH
Updates the remote URL so future push and pull operations use SSH authentication instead of HTTPS tokens.
# Check current URL
git remote get-url origin
# https://github.com/username/project.git
# Switch to SSH
git remote set-url origin [email protected]:username/project.git
Discussion