Set up SSH keys properly: Ed25519, a passphrase and the agent
Published history
Every published version keeps its original contributor and change message.
Current version
Retitle to match the heading
Contributor xIi_VH8g · 2026-10-28
Read exact source · Restore by submitting this source as a new revision.
Read this version
Set up SSH keys properly: Ed25519, a passphrase and the agent
SSH keys let you log in to servers and push to Git hosts without a password. Copied-and-pasted setups often end up with an outdated key type, no passphrase or the wrong file permissions. This guide does it properly in five steps.
What you need
- A terminal: macOS, Linux, or Windows 10/11 (OpenSSH is built in; use PowerShell)
- An account on the server or Git host you want to reach
1. Check for an existing key
ls -al ~/.sshid_ed25519andid_ed25519.pubexist: you already have a modern key. Skip to step 3.- Only
id_rsaexists: it still works if it is 3072 bits or more, but a new Ed25519 key is shorter, faster and the current default. - Nothing there, or the folder is missing: carry on.
2. Generate a key
ssh-keygen -t ed25519 -C "laptop-2026"- Press Enter to accept the default file location.
- Set a passphrase. It protects the key if the file is ever copied.
- The
-Ccomment is only a label. Name the device, not your email, so you can tell keys apart later.
3. Load the key into the agent
The agent holds the unlocked key, so you type the passphrase once per session instead of on every connection.
macOS and Linux:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519On macOS, use
ssh-add --apple-use-keychain ~/.ssh/id_ed25519to save the passphrase in Keychain.Windows (PowerShell as administrator, once):
Get-Service ssh-agent | Set-Service -StartupType Automatic Start-Service ssh-agent ssh-add $env:USERPROFILE\.ssh\id_ed255194. Give the public key to the other side
- Server:
ssh-copy-id user@host(macOS and Linux). On Windows, append the contents ofid_ed25519.pubto~/.ssh/authorized_keyson the server. - GitHub or GitLab: paste the contents of
id_ed25519.pubinto the SSH keys page of your account settings.
Only ever share the file ending in
.pub. The file without it is your private key.5. Test the connection
ssh -T git@github.comA greeting with your username means it worked. For a server,
ssh user@hostshould log you in without asking for the account password.Common mistakes and fixes
Mistake Symptom Fix Old DSA or short RSA key Server refuses the key Generate an Ed25519 key (step 2) Private key readable by others "UNPROTECTED PRIVATE KEY FILE", key ignored chmod 700 ~/.sshandchmod 600 ~/.ssh/id_ed25519No passphrase Anyone with a copy of the file can use it Add one: ssh-keygen -p -f ~/.ssh/id_ed25519Private key pasted into a website Key is compromised Remove it there, generate a new pair, share only the .pubSeveral keys, wrong one offered "Permission denied (publickey)" Add a Hostblock withIdentityFileandIdentitiesOnly yesto~/.ssh/configClearer title, Windows agent steps, expected test output, tighter wording, IdentitiesOnly in config fix
Contributor xIi_VH8g · 2026-10-28
Read exact source · Restore by submitting this source as a new revision.
Read this version
Set up SSH keys properly: Ed25519, a passphrase and the agent
SSH keys let you log in to servers and push to Git hosts without a password. Copied-and-pasted setups often end up with an outdated key type, no passphrase or the wrong file permissions. This guide does it properly in five steps.
What you need
- A terminal: macOS, Linux, or Windows 10/11 (OpenSSH is built in; use PowerShell)
- An account on the server or Git host you want to reach
1. Check for an existing key
ls -al ~/.sshid_ed25519andid_ed25519.pubexist: you already have a modern key. Skip to step 3.- Only
id_rsaexists: it still works if it is 3072 bits or more, but a new Ed25519 key is shorter, faster and the current default. - Nothing there, or the folder is missing: carry on.
2. Generate a key
ssh-keygen -t ed25519 -C "laptop-2026"- Press Enter to accept the default file location.
- Set a passphrase. It protects the key if the file is ever copied.
- The
-Ccomment is only a label. Name the device, not your email, so you can tell keys apart later.
3. Load the key into the agent
The agent holds the unlocked key, so you type the passphrase once per session instead of on every connection.
macOS and Linux:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519On macOS, use
ssh-add --apple-use-keychain ~/.ssh/id_ed25519to save the passphrase in Keychain.Windows (PowerShell as administrator, once):
Get-Service ssh-agent | Set-Service -StartupType Automatic Start-Service ssh-agent ssh-add $env:USERPROFILE\.ssh\id_ed255194. Give the public key to the other side
- Server:
ssh-copy-id user@host(macOS and Linux). On Windows, append the contents ofid_ed25519.pubto~/.ssh/authorized_keyson the server. - GitHub or GitLab: paste the contents of
id_ed25519.pubinto the SSH keys page of your account settings.
Only ever share the file ending in
.pub. The file without it is your private key.5. Test the connection
ssh -T git@github.comA greeting with your username means it worked. For a server,
ssh user@hostshould log you in without asking for the account password.Common mistakes and fixes
Mistake Symptom Fix Old DSA or short RSA key Server refuses the key Generate an Ed25519 key (step 2) Private key readable by others "UNPROTECTED PRIVATE KEY FILE", key ignored chmod 700 ~/.sshandchmod 600 ~/.ssh/id_ed25519No passphrase Anyone with a copy of the file can use it Add one: ssh-keygen -p -f ~/.ssh/id_ed25519Private key pasted into a website Key is compromised Remove it there, generate a new pair, share only the .pubSeveral keys, wrong one offered "Permission denied (publickey)" Add a Hostblock withIdentityFileandIdentitiesOnly yesto~/.ssh/configInitial publication
Contributor xIi_VH8g · 2026-10-28
Read exact source · Restore by submitting this source as a new revision.
Read this version
How to set up SSH keys
SSH keys let you log in to servers and push to Git hosts without typing a password. A lot of people get this working by copying commands from somewhere and end up with old key types, no passphrase, or the wrong file permissions. This guide goes through doing it properly.
What you need
- A terminal (macOS, Linux, or Windows 10/11 with OpenSSH, which is installed by default)
- Access to the server or Git host you want to connect to
Step 1: Check for existing keys
Run
ls -al ~/.ssh. If you seeid_ed25519andid_ed25519.pubyou already have a key and you might not need to make another one. If you only seeid_rsa, it's probably an older key and you may want to make a new Ed25519 one.Step 2: Generate a key
ssh-keygen -t ed25519 -C "you@example.com"Press Enter to accept the default location. When it asks for a passphrase, set one. The comment after
-Cis just a label so you can recognise the key later.Step 3: Add the key to the agent
The agent remembers your passphrase so you don't have to type it each time.
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519On macOS add
--apple-use-keychaintossh-addto store the passphrase in Keychain.Step 4: Copy the public key to where it's needed
- For a server:
ssh-copy-id user@host - For GitHub/GitLab: paste the contents of
~/.ssh/id_ed25519.pubinto the SSH keys page in your account settings
Never copy the file without
.pub. That's the private key.Step 5: Test it
ssh -T git@github.comfor GitHub, orssh user@hostfor a server.Common mistakes
Mistake What happens Fix Using RSA 1024 or DSA keys Modern servers refuse them Generate an Ed25519 key Private key permissions too open SSH ignores the key with "UNPROTECTED PRIVATE KEY FILE" chmod 600 ~/.ssh/id_ed25519andchmod 700 ~/.sshNo passphrase Anyone who copies the file can use it Set one with ssh-keygen -p -f ~/.ssh/id_ed25519Pasting the private key into GitHub Your key is compromised Delete it, generate a new pair, paste the .pubWrong key offered when you have several "Permission denied (publickey)" Add a Hostblock withIdentityFilein~/.ssh/config
Discussion 1
Next additions I'd make: a short ~/.ssh/config example for using separate keys for work and personal GitHub accounts, how to use a hardware security key (ssh-keygen -t ed25519-sk), and how to revoke a key from a server's authorized_keys when a laptop is lost.