Blog Set up SSH keys so you never type a password again
Set up SSH keys so you never type a password again
TL;DR Generate a key pair with ssh-keygen, keep the private key on your machine, and put the public key on the server or in GitHub. From then on you authenticate with the key instead of a password: faster, and far more secure than a password you could leak.
Typing a password every time you connect to a server or push to a repo is both slower and less secure than the alternative. SSH keys fix both. You set them up once and authenticate with cryptography from then on.
Generate a key pair
ssh-keygen -t ed25519 -C "you@example.com"
ed25519 is a modern, strong key type. Accept the default location, and set a passphrase when prompted, it encrypts the private key so a stolen laptop does not hand over access. You now have two files: id_ed25519 (private, keep secret) and id_ed25519.pub (public, safe to share).
Add the public key where you want in
To a server, copy your public key into its authorized keys:
ssh-copy-id you@your-server.com
To GitHub, copy the public key and paste it into Settings, SSH and GPG keys:
cat ~/.ssh/id_ed25519.pub # copy the output
The private key never leaves your machine. Only the public half goes out.
Type the passphrase once
Add the key to your SSH agent so the passphrase is remembered for the session:
ssh-add ~/.ssh/id_ed25519
Now connections and pushes just work, with no password prompt.
Test it
ssh -T git@github.com # GitHub greets you by name
ssh you@your-server.com # logs in with no password
Why it is worth the five minutes
A password can be guessed, phished, reused, and leaked. A key pair cannot be brute-forced in any realistic time, the private half never travels, and a passphrase protects it even if your machine is taken. You do this setup once, and every connection afterwards is faster and safer. Keep the private key private, back it up somewhere secure, and you are set.
FAQ
Are SSH keys more secure than passwords?
Yes. A key pair is far harder to brute-force than a password, and the private key never leaves your machine, so there is no password to phish or reuse. Add a passphrase to the key and even a stolen laptop does not hand over access.
What is the difference between the public and private key?
The private key stays secret on your machine and proves your identity. The public key is what you hand out, to a server or GitHub, and it can only verify the private key, not impersonate it. Never share the private key.
Should my SSH key have a passphrase?
Yes, for anything that matters. A passphrase encrypts the private key so it is useless if your machine is compromised. Use an agent so you type the passphrase once per session, not on every connection.