Articles

SSH Keys vs Password Authentication: Which Is Safer

SSH key pairs authenticate with cryptographic proof instead of a shared secret, resisting brute force and credential reuse in ways passwords structurally can't.

Chisato Chisato · · 4 min read
A set of keys on a ring

SSH key authentication proves identity with a cryptographic key pair instead of a shared secret, while password authentication relies on the server storing (or hashing) a copy of the same secret the client sends. Both let you log into a remote server over SSH, but they fail in very different ways, and that difference is why key-based auth is the accepted default for anything beyond a quick local test.

How each one proves identity

With password authentication, the client sends the password to the server, and the server checks it against a stored hash. Anyone who can guess, brute-force, or intercept that password can authenticate as you — the secret itself is the thing being transmitted and checked.

With SSH key authentication, you generate a key pair: a private key that never leaves your machine, and a public key you place in the server’s ~/.ssh/authorized_keys file. During login, the server sends a challenge, and your client signs it with the private key. The server verifies that signature using the public key it already has on file. The private key itself is never transmitted — only proof that you possess it. This is the same asymmetric-key idea behind how digital signatures work, applied to authentication instead of document signing.

Comparison

Password authenticationSSH key authentication
What’s transmittedThe password (over an encrypted channel)A signature, never the private key
Brute-force resistanceWeak — limited by password length/complexityStrong — private keys are typically 256+ bits of entropy
Reuse riskHigh — people reuse passwords across servicesLow — a key pair is generated per use case
RevocationChange the passwordRemove the public key from authorized_keys
Phishing resistanceNone — a fake prompt can capture itHigh — there’s nothing to “type into” a phishing page
SetupBuilt in, no extra stepRequires generating and distributing a key pair

Why brute force and credential stuffing don’t work against keys

A password is guessable — its strength is bounded by whatever length and character set a human was willing to type or a password manager was configured to generate. A brute-force or credential stuffing attack tries many passwords (or reused credentials leaked from other breaches) against a login endpoint, and it works often enough to remain one of the most common attack paths against exposed SSH servers.

An SSH private key, by contrast, is a randomly generated value with far more entropy than any password a person would realistically type — a modern Ed25519 key has 256 bits of entropy. There’s no meaningful way to guess it, and because it’s never transmitted during login, there’s nothing to intercept in transit even without SSH’s encryption doing that job already. Attackers automating login attempts against a server configured for key-only auth get nowhere no matter how many attempts they make, which is why disabling password authentication entirely (PasswordAuthentication no in sshd_config) is standard hardening advice for any internet-facing SSH server.

Where phishing resistance comes in

Because a password is just a string you type, a convincing fake login prompt can capture it — the same weakness that makes what a man-in-the-middle attack is possible against poorly configured connections, and part of why the industry is pushing toward passkeys replacing passwords more broadly. SSH keys sidestep this because there’s no secret value for a human to be tricked into typing anywhere — the private key file is used locally by your SSH client, and no login flow ever asks you to type or paste it.

Passphrase-protecting the private key

A private key file sitting unencrypted on disk is a single point of failure — anyone who copies that file can authenticate as you, no server involved. Setting a passphrase on the key encrypts it at rest, so a stolen key file alone isn’t enough; the passphrase is also required to use it. This is a local safeguard, not a replacement for keeping the key file itself out of reach — treat it with the same care you’d give any secret covered in secrets management.

Practical setup notes

Generating a key pair (ssh-keygen -t ed25519) and copying the public key to a server (ssh-copy-id) takes a couple of minutes and is a one-time setup per machine. From there, revoking access for a specific device is as simple as deleting its public key line from authorized_keys — no password rotation required, and no need to change a shared secret that other keys or services might also depend on.

When password auth still makes sense

Password authentication isn’t inherently broken for every context — a strong, unique password managed by a password manager, combined with multi-factor authentication, closes most of the gap for interactive human logins to general web services. But for SSH specifically, where automated key-based auth is just as easy to set up and closes off brute-force and phishing risk entirely, there’s little reason to keep password authentication enabled once keys are in place.

The takeaway

SSH keys replace a shared secret with cryptographic proof of possession, which makes them structurally resistant to brute force, credential reuse, and phishing in ways passwords aren’t. Setup takes a few minutes per machine; the payoff is a login method with no guessable secret and no exposure if login traffic is ever intercepted. For any server reachable over the internet, generating a key pair and disabling password authentication is a small effort for a real reduction in attack surface.

Chisato Chisato · · 4 min read

What Is a Replay Attack?

A replay attack resends a captured, valid message to trick a system into repeating an action — and why timestamps, nonces, and signatures stop it.

#Security #Authentication #Networking
Chisato Chisato · · 4 min read

What Is mTLS? Mutual TLS Authentication Explained

mTLS is TLS where both client and server present certificates, so each side cryptographically proves its identity before any data is exchanged.

#Security #Networking #Authentication