SSH vs HTTPS for Git Remotes — Which Should You Use?
Git repositories can be accessed over SSH (using key-based authentication) or HTTPS (using a username/password or personal access token).
Published September 29, 2026
HTTPS remotes authenticate with a token or credential helper over port 443; SSH remotes authenticate with a key pair over port 22. SSH is convenient once set up; HTTPS works through restrictive firewalls.
How it works
HTTPS URLs look like https://github.com/user/repo.git and need a personal access token (passwords are no longer accepted by GitHub).
SSH URLs look like git@github.com:user/repo.git and use your private key, optionally with ssh-agent for passphrase handling.
Try it
git remote -v
origin git@github.com:me/app.git (SSH)
git remote set-url origin https://github.com/me/app.git
Practical examples
Switch to SSH
git remote set-url origin git@github.com:me/app.gitGenerate a key
ssh-keygen -t ed25519 -C "me@example.com"
cat ~/.ssh/id_ed25519.pubTest the connection
ssh -T git@github.comCache HTTPS credentials
git config --global credential.helper storeCommon mistakes
- Using a password instead of a token over HTTPS.
- Committing private keys.
- Using SSH on a network that blocks port 22 without trying ssh over 443.
Key takeaways
- SSH = keys, HTTPS = tokens.
- Use whichever your network allows.
- Never share private keys.
FAQ
Which is more secure?
Both are secure when used properly; SSH keys avoid typing tokens.
What if port 22 is blocked?
Use ssh.github.com on port 443.