How to Generate and Manage Ed25519 SSH Keys for GitHub and Linux Servers
Using passwords for SSH logins or personal access tokens on every Git push is slow and leaves servers exposed to brute-force attempts. Modern Ed25519 SSH keys are shorter, faster, and stronger than older RSA keys, yet many developers still mix up .pub vs. private key files, skip passphrases, or lock themselves out of a VPS by disabling password authentication before testing key login.
Editorial illustration: generate a passphrase-protected keypair, organize hosts in ~/.ssh/config, and verify key login in a second terminal before hardening sshd.
Summary
- Generate an Ed25519 keypair (
ssh-keygen -t ed25519 -C "your_email@example.com") and always protect the private key with a strong passphrase. - Follow GitHub’s SSH key documentation by adding your key to
ssh-agent(or macOS Keychain) so you do not retype the passphrase on everygit push. - Use
~/.ssh/configwith separateIdentityFileentries when managing both GitHub and multiple Linux servers. - Before disabling password logins on a Linux server (
PasswordAuthentication no), test your SSH key in a second terminal window while keeping your first root/sudo session open.
Why Ed25519 is the default choice today
Older tutorials often show ssh-keygen -t rsa -b 4096. While 4096-bit RSA still works, Ed25519 provides equivalent or better cryptographic strength with much smaller keys, faster signature verification, and cleaner resistance to side-channel quirks. Unless you are connecting to a legacy appliance that literally does not support Ed25519, start with Ed25519 (or ed25519-sk if you use a FIDO2 hardware security key).
Step-by-step: Generate and configure Ed25519 SSH keys
1. Check for existing keys first
Before overwriting anything, inspect ~/.ssh/ as recommended in GitHub’s existing SSH keys guide:
ls -al ~/.ssh
If you already see id_ed25519 and id_ed25519.pub, decide whether to reuse them or save a new key under a dedicated filename like ~/.ssh/id_ed25519_work.
2. Generate the keypair with a passphrase
ssh-keygen -t ed25519 -C "your_email@example.com"
When prompted:
- Accept the default path (or specify a distinct name like
~/.ssh/id_ed25519_prod). - Enter a strong passphrase (stored in your password manager). Leaving the passphrase empty means anyone who copies your laptop’s
~/.ssh/folder can impersonate you immediately.
3. Add the key to ssh-agent and ~/.ssh/config
Start ssh-agent and load your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
On macOS, ssh-add --apple-use-keychain ~/.ssh/id_ed25519 saves the passphrase in your macOS Keychain. Then create or update ~/.ssh/config so each host picks the right key automatically:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host prod-web
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
Setting IdentitiesOnly yes stops SSH from trying five different keys in a row and hitting Too many authentication failures on strict servers.
4. Add only the .pub public key to GitHub or your Linux server
- For GitHub: Copy
~/.ssh/id_ed25519.puband paste it under Settings > SSH and GPG keys per GitHub’s guide on adding an SSH key. Verify with:ssh -T git@github.com - For a Linux server: Copy your public key to
~/.ssh/authorized_keyson the server usingssh-copy-id -i ~/.ssh/id_ed25519_prod.pub deploy@203.0.113.10.
5. Harden the Linux server without locking yourself out
- Keep your existing SSH session open as a safety net.
- Open a brand-new terminal tab and confirm
ssh prod-weblogs in using your key without asking for the server account password. - Only after confirming key login works, edit
/etc/ssh/sshd_config(or a drop-in file in/etc/ssh/sshd_config.d/) to setPasswordAuthentication noandPermitRootLogin prohibit-password, runsudo sshd -tto validate syntax, and reloadsshd.
For related Git and network troubleshooting workflows, see how to recover a Git commit after reset and debugging DNS propagation delays with dig and nslookup.
Common mistakes
- Copying the private key (
id_ed25519) instead of the.pubfile. Never paste or email your private key; servers and GitHub only ever need the single-line.pubfile. - Wrong file permissions on
~/.ssh. OpenSSH refuses to read keys if permissions are too loose. Keep~/.sshatchmod 700, private keys atchmod 600, andauthorized_keyson the server atchmod 600. - Closing your only SSH session before testing
sshd_configchanges. Always runsudo sshd -tand test a second connection before logging out. - Using one unencrypted key across personal GitHub, client servers, and production. Separate keys per role or at least protect every key with a passphrase and
IdentitiesOnly yes.
Why this matters
Clean SSH key management removes password prompts from daily Git deployments while blocking automated SSH password-guessing bots on Linux servers. Two extra minutes spent setting up ~/.ssh/config and IdentitiesOnly yes saves hours of authentication headaches later.
My Take
Always generate Ed25519 keys with a passphrase, store the passphrase in your password manager or macOS Keychain, and organize hosts in ~/.ssh/config from day one. When hardening a fresh Linux VPS, testing key login in a second terminal before reloading sshd is the one habit that guarantees you never lock yourself out.
Conclusion
Generate an Ed25519 keypair with ssh-keygen -t ed25519, load it into ssh-agent, configure IdentitiesOnly yes in ~/.ssh/config, upload only the .pub key to GitHub or authorized_keys, and test a fresh SSH session before disabling server passwords.