TechEarl

How to Create an SSH Key in 2026

Create an SSH key in one ssh-keygen command, then put it to work: install it on a server with ssh-copy-id, add it to GitHub or GitLab, and map multiple keys per host in ~/.ssh/config. Ed25519 vs RSA, adding, changing or removing a passphrase with ssh-keygen -p, and permissions, on Linux, macOS and Windows.

Ishan KarunaratnePublished ⏱️ 19 min readUpdated
Share thisCopied
Create an SSH key with ssh-keygen (Ed25519), add it to a server with ssh-copy-id or to GitHub and GitLab, and pick the right key per host in ~/.ssh/config.

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.

bash
ssh-keygen -t ed25519
Generating an Ed25519 SSH key with ssh-keygen, showing the randomart image
ssh-keygen creates the key pair and prints its randomart fingerprint.

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.

Try it with your own values

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:

bash· Linux (GNU)
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:

A terminal running ssh-keygen -t ed25519 as the user techearl: it prompts for a file location and passphrase, then prints the saved key paths, the SHA256 fingerprint, and the Ed25519 randomart image.
A real ssh-keygen run. The boxed 'randomart' is a visual fingerprint, handy for spotting at a glance whether a key changed.

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_ecdsa instead of id_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:

Terminal showing sudo ssh-keygen creating id_root_mistake owned by root:root inside techearl's ~/.ssh, then ssh-keygen failing with 'Permission denied' when the techearl user tries to read it.
The two id_root_mistake files are owned by root. As the normal user you cannot read your own key. Generate keys as yourself, every time.

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 typeWhen to use itNotes
Ed25519New keys, every modern systemShort keys, fast, security on par with RSA 4096. The right default in 2026.
RSA 4096Talking to genuinely old serversOnly needed for OpenSSH older than 6.5 (released 2014). Use -b 4096; never go below 3072 bits.
ECDSAOnly when a platform mandates itBuilt on NIST curves some operators distrust. Choose Ed25519 instead wherever you have the choice.
Ed25519-SK / ECDSA-SKHardware-backed keysNeeds 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:

bash· Linux (GNU)
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519

On 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:

bash· Linux (GNU)
ssh-keygen -p -f ~/.ssh/id_ed25519

It 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:

bash· Linux (GNU)
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.

bash· Linux (GNU)
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 && chmod 644 ~/.ssh/id_ed25519.pub

ssh-keygen already creates the files with the right modes, which you can see straight after generating:

ls -la of ~/.ssh showing the directory at drwx------ (700), the private key id_ed25519 at -rw------- (600), and the public key id_ed25519.pub at -rw-r--r-- (644), all owned by the techearl user.
What ssh-keygen leaves behind: 700 on the directory, 600 on the private key, 644 on the public one.

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:

Terminal showing the SSH 'WARNING: UNPROTECTED PRIVATE KEY FILE!' error after chmod 644 on a private key, stating permissions 0644 are too open and the key will be ignored, then chmod 600 to fix it.
The classic 'UNPROTECTED PRIVATE KEY FILE' wall. chmod 600 on the private key clears it.

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):

bash· Linux (GNU)
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server

ssh-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:

bash
# 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_keys

authorized_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:

  1. Wrong permissions on the server. sshd ignores ~/.ssh or authorized_keys if 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.
  2. Key not offered. Point at the right identity: ssh -i ~/.ssh/id_ed25519 user@server, or set IdentityFile in ~/.ssh/config (see using multiple SSH keys below).
  3. Server forbids key auth. Some hosts set PubkeyAuthentication no. You need server access to change sshd_config.
  4. Pasted the private key by mistake. Only the .pub file 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:

bash· Linux (GNU)
xclip -sel clip < ~/.ssh/id_ed25519.pub   # or: wl-copy < ~/.ssh/id_ed25519.pub

If 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).

Pasting an SSH public key into GitHub's New SSH key form
GitHub Settings, SSH and GPG keys, New SSH key: give it a title and paste the public key.
An SSH key listed in a GitHub account with its fingerprint
Once added, the key shows its fingerprint and access level. (This demo key has been deleted.)

Test it with ssh -T

This is the step people skip and then wonder why git push still fails:

bash
# GitHub
ssh -T git@github.com

# GitLab
ssh -T git@gitlab.com

GitHub 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:

bash
# 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.git

Clone 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.

code
# ~/.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:

bash
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.git

Personal 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:

bash
ssh -T git@github.com      # personal account
ssh -T git@work-git        # work account

GitHub 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

Sources

Authoritative references this article was fact-checked against.

TagsSSHssh-keygenEd25519SSH Keysssh-copy-idGitHubssh-configpassphraseLinuxmacOSWindows

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

How to store a phone number in MySQL: use VARCHAR not an integer, normalize to E.164 format, store it in VARCHAR(16), index for lookups, and keep the raw user input alongside it.

How to Store a Phone Number in MySQL

Store a phone number in MySQL as a string, never an integer. Normalize to E.164 and use VARCHAR(16), index it for lookups, and keep the raw input in a second column. Worked schema for MySQL and MariaDB.

Create a Linux user with useradd or adduser, then manage it: add a user to a group (usermod -aG), password, shell, list accounts, delete with userdel.

How to Create a User on Linux (useradd vs adduser)

Create a Linux user with useradd or adduser, then manage the account end to end: groups (and adding a user to a group with usermod -aG), passwords, login shells, listing accounts, and deleting a user cleanly with userdel.