>_ SSHDock
FeaturesHow it worksBlogGuidesAbout
Launch Terminal
Back to Journal

What is an SSH key? How it works and how to generate one

AH
Ayan Hussain
Jan 21, 2026 · 7 min read

On this page

  • Why use SSH keys instead of passwords?
  • How the authentication actually works
  • Key types
  • Generating your first SSH key
  • Adding your key to a server
  • Where your public key goes
  • Disabling password authentication
  • Managing keys across machines
  • Using SSH keys from a browser

An SSH key is a cryptographic key pair used to authenticate your identity when connecting to a server over SSH. You get two files: a private key that stays on your machine and a public key that you put on the server. When you connect, the server uses these two pieces to verify who you are, without ever transmitting a password.

Why use SSH keys instead of passwords?

Password logins have several problems. Passwords can be guessed. They can be phished. They can be leaked from a service breach where the same password was reused. And any server with port 22 open to the internet gets tested by automated bots cycling through common username and password combinations around the clock. Look at your /var/log/auth.log on a public Linux server and you will see thousands of failed attempts per day.

SSH keys sidestep all of this. A properly generated key is mathematically infeasible to brute-force: a 256-bit Ed25519 key would take longer than the age of the universe to break with current computing. The private key never leaves your machine during authentication. And once you switch to key-only auth and disable passwords, the bots get refused immediately rather than burning server resources testing combinations.

How the authentication actually works

SSH key authentication uses asymmetric (public-key) cryptography. The private and public keys are mathematically linked in a way that makes certain operations possible in only one direction.

When you connect to a server that has your public key in its authorized_keys file, the sequence goes like this:

  1. Your client tells the server which public key identity you want to use
  2. The server generates a random challenge (a large random number)
  3. The server encrypts that challenge with your public key
  4. Your client decrypts the challenge using your private key
  5. Your client derives a verification value from the decrypted challenge and sends it back
  6. The server checks the verification against the original challenge

Your private key performed the decryption locally and never left your machine. An observer watching the network traffic sees the challenge (encrypted, useless without the private key) and the verification value (also useless without knowing the original challenge). Neither reveals your private key.

This is fundamentally different from passwords, where the actual secret has to be transmitted to the server for verification. With key authentication, the proof of identity happens through computation, not transmission.

Key types

Ed25519

Ed25519 is based on elliptic curve cryptography over the Curve25519 curve. It produces 256-bit keys that are small, fast to generate, and fast to use. The security level is comparable to a 3000-bit RSA key. It is the recommended choice for all new SSH keys.

ssh-keygen -t ed25519 -C "your@email.com"

The -C comment is a label that helps you identify the key later. It appears at the end of the public key file and does not affect security.

RSA

RSA is the oldest SSH key type and has the widest compatibility. Old servers, old devices, and some embedded systems may only support RSA. Use a 4096-bit key:

ssh-keygen -t rsa -b 4096 -C "your@email.com"

The default RSA key size was 2048 bits for many years. That is still considered adequate but 4096 gives more margin against future improvements in factoring algorithms. For any new server where you control the SSH version, Ed25519 is better. For compatibility with older infrastructure, RSA at 4096 bits is the fallback.

ECDSA

ECDSA is another elliptic curve option. It is faster than RSA and widely supported. However, there have been concerns about the quality of random number generation in some implementations (notably, a poor random number generator has historically led to private key recovery from ECDSA signatures). Ed25519 uses a deterministic signature scheme that avoids this class of problem. Unless you have a specific reason to use ECDSA, Ed25519 is a better choice.

For a detailed comparison, see our RSA vs Ed25519 guide.

Generating your first SSH key

On Linux, macOS, or Windows with OpenSSH installed (available by default on Windows 10 and later):

ssh-keygen -t ed25519 -C "your@email.com"

The tool will ask two questions:

Where to save it: The default (~/.ssh/id_ed25519 for the private key and ~/.ssh/id_ed25519.pub for the public key) is fine for most situations. If you need separate keys for different purposes (personal vs. work, different clients), you can choose a different path and specify it when connecting.

Passphrase: Optional but recommended for any key used with important servers. A passphrase encrypts your private key file using your password, so if someone copies the file, they still cannot use it without the passphrase. You type the passphrase when SSH loads the key, not every time you connect (the key can be cached by ssh-agent for a session).

After generation, you have two files:

~/.ssh/id_ed25519      ← private key, keep this safe, never share it
~/.ssh/id_ed25519.pub  ← public key, this is what you put on servers

The public key file looks like this:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHt8... your@email.com

That entire string is what you copy to servers.

Adding your key to a server

The easiest way, if you can still log in with a password:

ssh-copy-id user@your-server

This command connects using your password, appends the public key to ~/.ssh/authorized_keys on the server, and sets the correct file permissions. After this, SSH will use the key for future connections.

If ssh-copy-id is not available on your system, do it manually:

cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Then verify the file permissions on the server. SSH will silently ignore your authorized_keys file if the permissions are wrong:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

If the .ssh directory is group-writable or authorized_keys is readable by others, SSH treats it as potentially tampered with and falls back to password authentication. This is a common source of confusion when setting up key auth.

Where your public key goes

The public key lives in ~/.ssh/authorized_keys on the server, for the user account you are connecting as. Each line in the file is one authorized public key. You can have multiple keys, one per line:

ssh-ed25519 AAAAC3Nz... personal laptop
ssh-ed25519 AAAAC3Mz... work desktop
ssh-rsa AAAAB3Nz...    old server key

Comments at the end of each line (the part after the key itself) are optional and are just for your reference.

Disabling password authentication

Once key auth is working, disable passwords to remove the attack surface that automated scanners probe. On the server, edit /etc/ssh/sshd_config:

PasswordAuthentication no
PubkeyAuthentication yes

Then reload: sudo systemctl reload sshd. Make sure your key is working before you do this. Locking yourself out of a remote server is inconvenient.

Managing keys across machines

If you work from multiple machines (a laptop and a desktop, or personal and work machines), you have options:

One key per machine is the more secure approach. Each machine has its own key pair. You add the public key from each machine to authorized_keys. If one machine is compromised, you remove that key without affecting the others.

One key for everything is more convenient. Keep the private key backed up securely and copy it to each machine you use. If the key is compromised, rotate everything at once.

Many people use one key per machine for servers they own and care about, and a shared key for less critical access. The right answer depends on your threat model.

Using SSH keys from a browser

SSHDock accepts RSA and Ed25519 private keys in PEM format. Paste the full contents of your private key file into the connection form. SSHDock stores it in your browser's local storage for future connections. The key never leaves your device.

If your key has a passphrase, SSHDock will ask for it when you connect. The passphrase is used locally to decrypt the key; it is not transmitted anywhere.

AH
Written by
Ayan Hussain

Full-Stack Developer and creator of SSHDock. Ayan builds browser-based developer tools and writes about SSH security, Linux server management, and modern web engineering.

About meGitHub

Keep reading

May 20, 2026

What is a bastion host?

A bastion host is a server that sits on the boundary between a private network and the internet. Here is what it does, why it exists, how to configure one, and when to consider alternatives.

Dec 30, 2025

What is SSH and how does it work?

SSH is the standard way to access remote servers securely. Here is how the protocol actually works, from the key exchange to authentication, without the hand-waving.

Oct 6, 2026

How to Fix 'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!'

Why you get the scary StrictHostKeyChecking warning in SSH, what a man-in-the-middle attack looks like, and how to safely clear out old known_hosts entries.

SSHDOCK

Full terminal in your browser. Local credential storage, jump host tunneling, live CPU/memory/disk metrics, and a mobile soft-key bar. Free to use. Built by developers, for developers.

© 2026 SSHDock

GitHub (@ayanhackspro)
App
Launch TerminalFeaturesHow it worksBlog & TutorialsChangelogGuides
Cloud Guides
AWS EC2DigitalOcean DropletGoogle Cloud Compute EngineMicrosoft Azure Virtual MachineLinode Compute InstanceVultr Cloud Compute
Legal & Contact
Privacy PolicyTerms of ServiceDisclaimerContact UsAbout Creator
Modern, minimal browser SSH client
TerminalSitemap