Network security

What Is an SSH Key? How Public and Private Keys Work in 2026

An SSH key replaces a password with a cryptographic key pair: the private key stays on your computer and signs, the public key sits on the server and verifies. Here is how to use one safely.

Cysoro Security TeamPublished · 9 min read
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5...public key — safe to share NETWORK SECURITY SSH keys Log in without sending a password.
Quick answer

An SSH key is a pair of cryptographic keys used to log into servers over SSH without a password. The private key stays on your computer and must be kept secret; the public key is placed on the server, where it verifies that you hold the matching private key. When you connect, you sign a challenge with the private key and the server checks it — the secret itself never travels over the network.

Key takeaways

  • An SSH key pair replaces a password: the private key signs on your computer, the public key verifies on the server.
  • Ed25519 is the recommended key type in 2026 — a 256-bit key, fast and supported by current OpenSSH, GitHub and cloud providers.
  • Always protect the private key with a passphrase, never share it, and remove it from servers when it is lost or no longer needed.

Passwords are the weakest link in server access: they can be guessed, phished or reused. An SSH key replaces the password with cryptography — a key pair in which the secret never leaves your computer, yet the server can still be sure it is you.

What is an SSH key?

An SSH key is a pair of cryptographic keys used to log into servers over SSH, the Secure Shell protocol, without a password. One key is private and stays with you; the other is public and is placed on every server you want to access.

SSH, or Secure Shell, is the encrypted protocol used to administer servers, transfer files and run remote commands. SSH keys provide a more secure authentication method than passwords, because password authentication can be vulnerable to brute-force attacks while keys use cryptographic proof instead.

DigitalOcean's guide to configuring SSH key-based authentication explains the same trade-off: keys are far harder to attack than passwords, and they remove the brute-force target entirely.

You will meet SSH keys when you set up a cloud server, push code to GitHub or GitLab, or connect to a work server from a terminal. Most modern services expect you to use one, and many cloud providers disable password login entirely.

How does an SSH key work?

An SSH key works by signature, not by sending a secret. The server asks for proof that you hold the private key; you sign a challenge with it, and the server verifies the signature with your public key. The private key never travels over the network.

How SSH key login works 1 Challenge server sends a unique challenge 2 Sign private key signs it on your device 3 Verify server checks the signature publicly 4 Access signature matches, session opens The private key never leaves your computer at any step.
SSH authentication proves possession of the private key without sending it. Illustration by Cysoro.

With a password, the secret travels to the server — inside the encrypted tunnel, but it arrives on the other side, where the server compares it with what it has stored. With a key, the secret never leaves your computer at all.

Before any of that, the server proves its own identity too. Every SSH server has its own key pair, the host key, and your client checks it against the copy stored in ~/.ssh/known_hosts. If the host key changes unexpectedly, SSH warns you — a protection against connecting to an impostor server.

The connection itself is encrypted end to end, including authentication, so it is protected against eavesdropping and connection hijacking. That is why SSH replaced older tools such as Telnet, which sent passwords in plain text.

Public key vs private key: what is the difference?

The two keys do opposite jobs, and confusing them is the most common SSH mistake. The private key signs and must stay secret; the public key verifies and can be shared freely.

Private keyPublic key
Where it livesYour computer, in ~/.ssh/id_ed25519Servers, in ~/.ssh/authorized_keys, and services such as GitHub
What it doesSigns challenges to prove who you areVerifies those signatures
Can it be shared?Never — anyone with it can log in as youYes — it cannot sign, so it is safe to publish
FileNo extension, e.g. id_ed25519Ends in .pub, e.g. id_ed25519.pub
If lostYou lose access; if stolen, revoke it everywhereJust regenerate it from the private key

The public key file is one line of text with three parts separated by spaces: the type (ssh-ed25519), the key in base64, and a comment, usually your email address. That is the line you paste into GitHub or into a server's authorized_keys file.

The private key can be recomputed into the public key, so losing the .pub file is not a problem. The other direction does not exist: you cannot derive a private key from a public one, and that is what lets the public key be public.

If the private key is protected by a passphrase, it is stored encrypted on disk — with AES-256, and the encryption key derived from your passphrase. A stolen file alone is not enough to use it.

Which SSH key type should you use?

Ed25519 is the recommended key type in 2026. It is a 256-bit key, fast, and supported by current macOS, Linux and Windows OpenSSH, and by GitHub, GitLab and major cloud providers. Since OpenSSH 9.5, Ed25519 is the default type.

For a deep look at how the key types differ internally, see David Costa's guide to how SSH keys work, which walks through Ed25519, RSA and host keys with real OpenSSH output.

Key typeStrengthWhen to use it
Ed25519256-bitDefault choice for all new keys
RSA3072-bit minimumOnly when an old server does not support Ed25519
ECDSA256-bit or 384-bitRarely needed; Ed25519 is preferred
DSAWeakNever — deprecated and disabled in modern OpenSSH

Security keys such as YubiKeys add another option: Ed25519-SK and ECDSA-SK keys store the private key on the hardware device, so it cannot be copied off the computer at all. For administrators and anyone with access to production systems, that is worth considering.

Avoid DSA entirely. It is deprecated, and modern OpenSSH disables it. RSA is fine when you need it, but use at least 3072 bits — 2048-bit RSA is still accepted, yet 3072 is the safer minimum for a key you expect to keep for years.

How do you create an SSH key?

Creating a key takes one command and under a minute. The tool is ssh-keygen, built into Linux, macOS and modern Windows.

  1. Generate the key. Run ssh-keygen -t ed25519 -C "[email protected]" in a terminal. The -C comment is just a label so you can tell keys apart later.
  2. Choose where to save it. Accept the default, ~/.ssh/id_ed25519, unless you already have a key there — in that case, give the new one a different name.
  3. Set a passphrase. Type a strong passphrase twice. Use a passphrase you can remember, or generate one with our free password generator and store it in a password manager.
  4. Copy the public key to the server. Run ssh-copy-id user@server, which installs the public key into the server's ~/.ssh/authorized_keys file. For GitHub, paste the contents of id_ed25519.pub into Settings, then SSH keys.
  5. Test the login. Run ssh user@server. It should ask for your key passphrase, not your account password, and then open a session.
  6. Disable password login. Once key login works, turn off password authentication on the server. That removes the brute-force target entirely.

On Windows, use PowerShell, Windows Terminal, or Windows Subsystem for Linux. The commands and file locations are the same, except the home folder is C:\Users\username\.ssh.

If you use an SSH agent, you can add your key once per session with ssh-add and avoid typing the passphrase for every connection. The agent holds the decrypted key in memory, so lock your screen when you step away.

SSH keys vs passwords: which is safer?

SSH keys are safer than passwords for server access, for three reasons: the secret never travels, the key space is far larger, and keys cannot be phished in the usual way.

A password can be guessed by brute force, especially a weak or reused one. An Ed25519 key has 256 bits of entropy — there is nothing to guess. A password can also be captured by a fake login page. An SSH key signs a challenge that is specific to that connection, so a captured signature cannot be replayed on another server.

Keys also enable automation. Scripts, backups and deployment tools can authenticate without a password stored in plain text — though for automation, use a dedicated key with no passphrase and restricted permissions, never your personal key.

Passwords still have a role: as the passphrase protecting your private key, and as a fallback for accounts that do not support keys. Use a password manager, and check the strength of any passphrase with our password strength checker.

How do you manage SSH keys securely?

Most SSH incidents are not cryptographic failures. They are management failures: a key copied to a shared laptop, an ex-employee's key left on a server, or a private key committed to a code repository.

SSH key security checklist Passphrase on every key Encrypts the private key on disk. A stolen file alone is useless. One key per purpose Separate keys for GitHub, work and personal servers. Check file permissions Private key readable only by you (chmod 600) or SSH refuses it. Revoke fast when lost Remove the public key from every server and service.
Four habits that keep SSH keys safe. Illustration by Cysoro.
  • Never share a private key. Not by email, not in chat, not in a shared folder. If someone needs access, they generate their own key pair.
  • Never commit a private key to code. Check repositories for leaked keys, and use secret scanning on GitHub. A key in git history stays compromised even after you delete the file.
  • Set file permissions. Your private key should be readable only by you (chmod 600 ~/.ssh/id_ed25519). OpenSSH refuses keys with loose permissions.
  • Use separate keys per purpose. One for GitHub, one for work, one for personal servers. Revoking one then breaks nothing else.
  • Audit authorized keys regularly. List who has access to each server and remove keys for people who left, projects that ended and laptops that were replaced.
  • Rotate after any doubt. If a laptop is lost or a key may have been copied, generate a new pair and remove the old public key everywhere.

For teams, SSH certificates are the better long-term answer. A certificate authority signs short-lived certificates, so access expires automatically and there is no authorized_keys file to manage. That is more setup, but it removes the stale-key problem entirely.

If your private key may be compromisedGenerate a new key pair immediately, remove the old public key from every server and service, and check server logs for logins you do not recognize. Do not wait to confirm the compromise — revocation is cheap and a breach is not.

What if your SSH key does not work?

Most SSH key failures have boring causes. Work through them in order before regenerating anything.

  • Permission denied (publickey). The server does not have your public key, or it is in the wrong authorized_keys file. Check the username, the server, and that ssh-copy-id succeeded.
  • Wrong key offered. Your agent may offer a different key first. Use ssh -i ~/.ssh/id_ed25519 user@server to name the key explicitly.
  • Bad permissions. The private key, the .ssh folder or authorized_keys may be too open. SSH is strict about this and will refuse to use the key.
  • Passphrase forgotten. There is no recovery. Generate a new key pair and replace the old public key everywhere.
  • Host key changed. SSH warns you if a server's host key differs from the one in known_hosts. Do not accept it blindly — confirm with the server owner, because it can mean an impostor or a rebuilt server.

Run ssh -v user@server for verbose output. It shows which keys were offered and why each was rejected, which usually points straight at the problem.

For home networks, pair key-based login with the basics in our guide on how to secure your Wi-Fi, so the server is not the only hardened part of your setup.

The bottom line

An SSH key is a public-private key pair that lets you log into servers without sending a password over the network. The private key stays on your computer and signs; the public key sits on the server and verifies. Ed25519 is the right default in 2026.

Generate a key with ssh-keygen -t ed25519, protect it with a strong passphrase, copy only the public key to your servers, and disable password login once it works. Then audit your keys regularly — a key you forgot about is a door you forgot to lock. Generate a strong passphrase with the free password generator to protect yours.

Frequently asked questions

What is an SSH key in simple terms?

An SSH key is a pair of digital keys that lets you log into a server without typing a password. The private key stays on your computer and proves who you are; the public key sits on the server and checks that proof.

Is an SSH key the same as a password?

No. A password is a secret you send to the server, which compares it with what it has stored. An SSH key never leaves your computer: you use the private key to sign a challenge, and the server verifies the signature with your public key.

Which SSH key type should I use?

Use Ed25519. It is a 256-bit key, fast, and the default in OpenSSH since version 9.5. Use RSA with at least 3072 bits only when an old server or service does not support Ed25519.

Can I share my public SSH key?

Yes. The public key is designed to be shared freely: it can verify signatures but cannot sign, so it cannot be used to log in as you. GitHub even publishes users' public keys at github.com/username.keys.

What happens if I lose my private SSH key?

You lose access from that computer until you add a new public key to the server, usually by logging in another way or asking an administrator. If the private key may have been stolen, remove its public key from every server at once.

Do SSH keys expire?

Standard SSH keys do not expire. That is why rotation and removal matter: an old key left on a server stays valid indefinitely. SSH certificates can add expiry, and are the better option for larger teams.

Should my SSH key have a passphrase?

Yes. A passphrase encrypts the private key on disk, so a stolen laptop or copied file is not enough to use it. Use a strong passphrase and a password manager or SSH agent so you do not have to type it constantly.

Can I use one SSH key for many servers?

You can, but it is safer to use separate keys for separate purposes, such as one for GitHub, one for work servers and one for personal servers. That way, removing one key does not break everything else.

Sources

  1. DigitalOcean — How to Create an SSH Key in Linux
  2. David Costa — SSH keys from the inside: how they work, the types and the risks
  3. openSUSE — Securing network operations with OpenSSH
  4. Carleton University — Passwordless SSH With Key Pairs
  5. Hostinger — Learn how to set up SSH keys and manage them effectively
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against OpenSSH documentation and guides from DigitalOcean, openSUSE and Carleton University, with Ed25519 as the recommended default.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free