To create an SSH key, run ssh-keygen -t ed25519 as your normal user. It writes a private key and a matching .pub public key into ~/.ssh. The public half then goes on servers (with ssh-copy-id) and into GitHub or GitLab, while the private half never leaves your machine. This page covers all of it: generating the key, changing or removing its passphrase later, installing it, and running several keys side by side.
ssh-keygen -t ed25519
That command has not meaningfully changed since your 2014 self typed it. What changed by 2026 is not the how, it is the which: which key type to pick (Ed25519, not RSA), whether to bother with a passphrase, and where the two files have to live so SSH actually trusts them. Here is the whole thing, on Linux, macOS, and Windows.
Pick your OS and key type. The commands below update to match. Ed25519 is the right default in 2026; only change it if something forces you to.
The one command
This is the whole job. It is identical on Linux, macOS, and Windows because ssh-keygen ships with OpenSSH everywhere:
ssh-keygen -t ed25519 -C "you@example.com"The -C comment is just a label that ends up at the end of the public key, so future-you can tell keys apart. Press Enter at every prompt to accept the default path (~/.ssh/id_ed25519) and an empty passphrase, or fill them in. That is what a real run looks like:

You now have two files in ~/.ssh: the private key (id_ed25519, keep it secret, never copy it anywhere) and the public key (id_ed25519.pub, safe to hand out). That is the entire mental model: the public half goes on servers and into GitHub; the private half stays on your machine and never moves.
If you picked RSA or ECDSA in the box above, your files are named
id_rsa/id_ecdsainstead ofid_ed25519. Swap the name in the commands below to match.
Do I need sudo? (No, and please don't)
Creating a key is a per-user action. It writes to your home directory, so it needs no root and no sudo. This trips people up because so many Linux tutorials reflexively prepend sudo to everything.
sudo ssh-keygen is actively wrong: it creates a key owned by root, sitting in your ~/.ssh, that you then cannot read. SSH refuses keys it cannot open as you:

The rule that actually matters: run a command with the privilege the task needs, not out of habit. Creating your own key is a you-level task. Adding that key to another user's account on a server, or editing system config, is a root-level task where sudo (or logging in as that user) is correct. Reach for elevation deliberately, not by reflex.
Which key type should I pick in 2026?
Ed25519, in almost every case. Pass -t ed25519 and stop thinking about it. (A 2026 footnote on that opening joke: since OpenSSH 9.5, released 2023, bare ssh-keygen with no flags already creates an Ed25519 key. I still pass -t ed25519 explicitly so the command does the right thing on older machines that still default to RSA.)
| Key type | When to use it | Notes |
|---|---|---|
| Ed25519 | New keys, every modern system | Short keys, fast, security on par with RSA 4096. The right default in 2026. |
| RSA 4096 | Talking to genuinely old servers | Only needed for OpenSSH older than 6.5 (released 2014). Use -b 4096; never go below 3072 bits. |
| ECDSA | Only when a platform mandates it | Built on NIST curves some operators distrust. Choose Ed25519 instead wherever you have the choice. |
| Ed25519-SK / ECDSA-SK | Hardware-backed keys | Needs OpenSSH 8.2+ and a FIDO2 device (YubiKey and similar). The private half physically never leaves the hardware. |
DSA is gone: it was capped at 1024 bits, disabled by default for years, and OpenSSH removed it outright in version 10.0 (2025). If something still asks for a DSA key in 2026, that system is the problem, not your tooling.
Ed25519 works out of the box on current Linux, macOS, and Windows, since all three ship a modern OpenSSH. The only place you will hit trouble is a server or appliance that has not been updated in a decade, which is the one scenario where RSA 4096 earns its place.
Should I add a passphrase?
Honest answer: on machines I physically control and keep disk-encrypted, I often don't. But I am going to tell you to anyway, and it would be remiss of me as a security person to say otherwise.
The moment the key lives on a laptop that can be lost, or a box other people can touch, the passphrase is the only thing standing between a stolen private key and every server that trusts it. And ssh-agent means you type it once per session, so the day-to-day cost is essentially nothing. So: set a passphrase. Do as I say, not as I sometimes do.
You do not have to decide at creation time. You can add, change, or remove the passphrase on an existing key whenever you like, as the next section shows.
Load the key into the agent once so the passphrase prompt stops following you around:
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519On macOS, --apple-use-keychain stores the passphrase in the Keychain so it survives reboots. On Windows, the ssh-agent service is disabled by default; the Start-Service line wakes it up (run it once as administrator to set it to start automatically).
Change or remove an SSH key passphrase
The passphrase encrypts the private key file at rest. It is independent of the keypair itself, so you can add, change, or remove it any time without regenerating anything. The public key and the SHA256 fingerprint stay the same, so nothing on any server or in GitHub needs reinstalling.
To change a passphrase, or add one to a key that never had one, run ssh-keygen -p:
ssh-keygen -p -f ~/.ssh/id_ed25519It prompts for the old passphrase (press Enter if there is none), then the new one twice.
To remove the passphrase, set the new one to empty: press Enter at the "new passphrase" prompts, or do it non-interactively with -N:
ssh-keygen -p -f ~/.ssh/id_ed25519 -N ''Removing a passphrase is convenient for unattended jobs (CI, cron, deploy keys), but a stolen key file is then immediately usable. Only do it on machines you control, and prefer a dedicated, narrowly scoped deploy key over your personal key for automation. If the prompt is the only reason you want the passphrase gone, keep it and load the key into ssh-agent once per session as shown above; that gives you the security of a passphrase with the convenience of none.
Forgot the passphrase? There is no recovery, because it is not stored anywhere. Generate a new key and reinstall its public half wherever the old one was trusted.
Where the keys live, and the permissions that matter
Your keys sit in ~/.ssh on Linux and macOS, and %USERPROFILE%\.ssh on Windows. The permissions are not cosmetic: SSH flat-out refuses to use a private key that other users can read.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 && chmod 644 ~/.ssh/id_ed25519.pubssh-keygen already creates the files with the right modes, which you can see straight after generating:

So you usually only need the chmod above when you copied keys over from another machine and the permissions came along too loose. Here is the error that produces, and the fix:

If 600 and 700 look cryptic, they are octal file modes: 600 is read and write for you and nobody else, 700 adds execute (the bit that lets you enter a directory), again for you only. Anything that grants group or other a bit on the private key is what trips the warning. Staring at that error on a key you copied from another machine? Here is the full fix for SSH "permissions are too open".
Add an SSH key to a server
The public key is the half you share. Logging into a server without a password means installing that public half in the server's ~/.ssh/authorized_keys for the account you log in as. On Linux and macOS that is one command, ssh-copy-id; Windows OpenSSH has no ssh-copy-id, so you append the key over SSH instead (the Windows command creates ~/.ssh first, since it may not exist on a fresh account):
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@serverssh-copy-id logs in once with your password, creates ~/.ssh on the server if needed, appends your public key to ~/.ssh/authorized_keys, and fixes the permissions. After that, the password is no longer needed. Confirm it: ssh user@server should log you straight in with no password prompt. No sudo anywhere here either: you are writing into your own account on the server.
The manual way (what ssh-copy-id does under the hood)
ssh-copy-id is a convenience wrapper. The actual job is "append my public key to the server's ~/.ssh/authorized_keys", and you can always do it by hand, which is the only option on Windows and on locked-down servers:
# 1. Print your PUBLIC key locally (never the private one)
cat ~/.ssh/id_ed25519.pub
# 2. On the server, create ~/.ssh and paste the key in
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-ed25519 AAAA... you@example.com" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysauthorized_keys is just a list of public keys, one per line. Each line that is present can log in as that user. If WSL is installed on Windows, the Linux ssh-copy-id works inside it.
On AWS, GCP, and most cloud providers you hand the public key to the platform at launch and it places the key for you. See how to SSH into an EC2 instance and how to SSH into a GCP VM without gcloud for the provider-specific paths.
Still prompted for a password?
In order, the usual causes:
- Wrong permissions on the server.
sshdignores~/.sshorauthorized_keysif they are group- or world-writable. On the server:chmod 700 ~/.ssh,chmod 600 ~/.ssh/authorized_keys. This is the permissions-too-open problem, server side. - Key not offered. Point at the right identity:
ssh -i ~/.ssh/id_ed25519 user@server, or setIdentityFilein~/.ssh/config(see using multiple SSH keys below). - Server forbids key auth. Some hosts set
PubkeyAuthentication no. You need server access to changesshd_config. - Pasted the private key by mistake. Only the
.pubfile goes on the server. If you ever pasted the private key anywhere, rotate it.
If you hit Permission denied (publickey) instead of a password prompt, the key was generated fine but the server is not accepting it yet, which is a separate problem from key creation. Once key login is solid, the security payoff is hardening sshd to disable password authentication entirely so brute-force attempts have nothing to guess.
Add an SSH key to GitHub and GitLab
Adding the key to GitHub or GitLab is the same idea as adding it to a server: the public half goes on their side, the private half stays on yours. The only difference is that you paste it into a settings page instead of running ssh-copy-id. Copy the public key to the clipboard first:
xclip -sel clip < ~/.ssh/id_ed25519.pub # or: wl-copy < ~/.ssh/id_ed25519.pubIf those tools are not installed, just cat ~/.ssh/id_ed25519.pub and copy the single line by hand. It starts with ssh-ed25519 and ends with your comment. Then paste it into the web UI:
- GitHub: Settings, then SSH and GPG keys, then New SSH key. Give it a title (the machine name is useful), leave the type as Authentication Key, paste, and save.
- GitLab: Preferences, then SSH Keys, then Add new key. Paste, optionally set an expiry, and save.
You are pasting the contents of the .pub file. Never paste the private key (the file with no extension).


Test it with ssh -T
This is the step people skip and then wonder why git push still fails:
# GitHub
ssh -T git@github.com
# GitLab
ssh -T git@gitlab.comGitHub replies Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access. That sentence is success, not an error: GitHub authenticated the key but only allows git operations, not a login shell. GitLab says Welcome to GitLab, @USERNAME!. The first time you connect you will be asked to trust the host key; type yes. If ssh -T fails to authenticate, work through Permission denied (publickey) before touching anything else.
Use the SSH remote, not HTTPS
A key only helps if the repo uses the SSH remote URL (git@...), not HTTPS. An HTTPS remote ignores SSH keys entirely, which is why GitHub can still ask for a username and password on push after you added the key:
# Check the current remote
git remote -v
# Switch an existing repo from HTTPS to SSH
git remote set-url origin git@github.com:owner/repo.gitClone with the SSH URL from the start (the green Code button, SSH tab) and git clone, pull, and push use the key automatically with no prompts, and no personal access token. If you are still weighing an SSH or HTTPS remote for GitHub, that comparison is worth a read, and why Git asks for a password covers the background.
Use multiple SSH keys
If you keep separate SSH keys (work versus personal, prod versus staging, one GitHub account versus another), the problem is making SSH pick the right one automatically. The answer is ~/.ssh/config: bind each key to its host with an IdentityFile line plus IdentitiesOnly yes.
Why it matters: by default SSH offers every key it can find, in order, until one works or the server cuts you off (MaxAuthTries, usually 6). With several keys loaded you can exhaust that limit before the correct key is tried, and the server returns Too many authentication failures. Or the server accepts the first valid key, which may belong to the wrong account.
# ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host work-git
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host prod
HostName prod.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
IdentitiesOnly yes is the important line: it stops SSH from offering any key except the listed IdentityFile (ignoring keys loaded in the agent), which is what prevents the "too many failures" cutoff. Create each extra key with ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work and the same rules as above apply.
Two GitHub accounts on one machine
This is the classic case. GitHub identifies you by the key, not the URL, so you cannot use git@github.com for both. Use a host alias for the second account (the work-git block above), then point the repo at the alias:
git clone git@work-git:company/repo.git
# or change an existing repo's remote:
git remote set-url origin git@work-git:company/repo.gitPersonal repos keep using git@github.com:...; work repos use git@work-git:.... Each resolves to github.com but offers a different key. Test which identity each alias maps to:
ssh -T git@github.com # personal account
ssh -T git@work-git # work accountGitHub answers Hi USERNAME! with the account the offered key belongs to, so you can confirm each alias maps to the right identity. The full reference for connecting, tunneling, and copying over SSH is in the SSH cheat sheet.
One thing not to do: online SSH key generators
Do not generate SSH keys on a website. A private key is a secret that should be born and die on your own machine. If a site generates the keypair for you, the private half existed on someone else's server first, which means you have to trust that they did not log it, and you can never prove they didn't. Key generation is the one step that must stay local. ssh-keygen is right there, it is offline, and it takes one line.
FAQ
Ed25519. It is faster, the keys are far shorter, and its security is on par with RSA 4096. Run ssh-keygen -t ed25519 and move on.
Pick RSA only if you must reach a server running OpenSSH older than 6.5 (released 2014), and then use ssh-keygen -t rsa -b 4096. Anything below 3072 bits is considered weak.
You should set one, especially on a laptop or any shared machine. The passphrase encrypts the private key at rest, so a stolen key file is useless without it. With ssh-agent you type it once per session, so the ongoing cost is tiny.
An empty passphrase is only defensible on a machine you fully control and keep disk-encrypted, and even then it is a convenience trade-off, not a security win.
No. The passphrase only encrypts the private key file on disk. The keypair, the public key, and the SHA256 fingerprint are unchanged, so nothing on any server or in GitHub needs updating.
No. ssh-keygen writes into your own ~/.ssh, so it runs as your normal user with no elevation. Using sudo creates a key owned by root that you then cannot read, and SSH will refuse it. Generate keys as yourself.
In ~/.ssh on Linux and macOS, and %USERPROFILE%\.ssh on Windows. The default Ed25519 keypair is id_ed25519 (private) and id_ed25519.pub (public). The directory should be mode 700 and the private key 600.
Yes, and most people do. The common pattern is one key per machine you log in from: your laptop has a single keypair, and that one public key goes into the authorized_keys of every server plus your GitHub account. If the laptop is compromised you rotate one key, not dozens.
Use separate keys only when you want to isolate concerns, for example work versus personal, and bind each to its hosts in ~/.ssh/config. Using multiple SSH keys above walks through the Host and IdentityFile entries that pick the right key per server automatically.
None, functionally. ssh-copy-id automates exactly what you would do by hand: it appends your public key to the server's ~/.ssh/authorized_keys and sets the permissions. Editing the file manually is the fallback when ssh-copy-id is not available (Windows) or the server blocks it.
The repo is using the HTTPS remote, which ignores SSH keys. Check with git remote -v; if it shows https://github.com/..., switch it: git remote set-url origin git@github.com:owner/repo.git. SSH keys only apply to git@ remotes, and with one you do not need a personal access token at all.
Create a second key, add it to the second account, and define a Host alias in ~/.ssh/config (for example work-git) with its own IdentityFile and IdentitiesOnly yes. Clone work repos with git@work-git:owner/repo.git and personal repos with git@github.com:owner/repo.git.
SSH offered several wrong keys first and hit the server's MaxAuthTries limit before reaching the right one. Pin the key per host with IdentityFile and add IdentitiesOnly yes so only that key is offered.
id_ed25519 is the private key. It is the secret; it never leaves your machine and you never paste it anywhere. id_ed25519.pub is the matching public key, which is safe to share: it is what you install on servers and paste into GitHub. They are a mathematically linked pair, and a server proves it trusts you by checking that you hold the private half.
The command is the same. Windows 10 (1809) and later ship OpenSSH, so ssh-keygen -t ed25519 works in PowerShell exactly as on Linux. The differences are cosmetic: keys live in %USERPROFILE%\.ssh, permissions use NTFS ACLs instead of chmod, the ssh-agent is a Windows service you start once, and there is no ssh-copy-id (you append the public key to the server manually).
See also
- SSH Cheat Sheet: once the key exists, this is the reference for connecting, port forwarding, ProxyJump, scp, and rsync.
- Linux file permissions and ownership with find: the read/write/execute and ownership model behind the
chmod 600your key needs. - How to SSH into an EC2 instance: putting the key you just made to work against an AWS box.
- How to SSH into a GCP VM without gcloud: the same, for Google Cloud, using your own key instead of the gcloud helper.
- back the key with a YubiKey (FIDO2): move the private half onto hardware you cannot copy it off.
- Show an SSH login banner before authentication: set the server-side message users see when they connect with the key, before the prompt.
- If you made this key to start using Git and GitHub, the rest of the Git basics pick up from here: cloning, committing, and pushing over the SSH remote.
Sources
Authoritative references this article was fact-checked against.
- ssh-keygen(1) manual page (OpenBSD)man.openbsd.org
- Generating a new SSH key and adding it to the ssh-agent (GitHub Docs)docs.github.com
- OpenSSH key management on Windows (Microsoft Learn)learn.microsoft.com
- OpenSSH release notesopenssh.com
- Adding a new SSH key to your GitHub account (GitHub Docs)docs.github.com
- Use SSH keys to communicate with GitLab (GitLab Docs)docs.gitlab.com
- ssh-copy-id(1) manual page (OpenBSD)man.openbsd.org
- ssh-copy-id(1) Linux manual page (man7.org)man7.org
- sshd(8) manual page (OpenBSD, authorized_keys)man.openbsd.org
- ssh_config(5) manual page (OpenBSD)man.openbsd.org
- ssh-agent(1) manual page (OpenBSD)man.openbsd.org





