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

  1. Generate a key with ssh-keygen.
  2. Copy the public key (.pub file).
  3. Paste it into GitHub β†’ Settings β†’ SSH and GPG keys.

Example

Example Β· bash
# 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.

Example Β· bash
# 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 keys

Test SSH connection to GitHub

Confirms the SSH key is correctly registered; a successful handshake means push and pull will work without a password.

Example Β· bash
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.

Example Β· bash
# 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

  • Be the first to comment on this lesson.
HTTPS vs SSH Keys β€” GitHub | SoundsCode