skip to content

Authentication Methods

Clients prove identity by public key, password, keyboard-interactive or a CA-signed certificate, and sshd can demand several. Interviewers like certificates because authorized_keys does not scale.

on this pageshow

questions

6

In SSH, what does the server receive and keep for password authentication compared with public-key authentication, and why is the key login safer?

level: juniorimportance: must knowfreq 68%

answer

  1. what crosses the encrypted channel
  2. secret versus proof of possession
  3. server keeps only the public half
  4. the passphrase never leaves the client
  5. what a compromised server learns

basics

~20 s

With SSH password authentication the client sends the password itself, hidden only by the transport encryption, and the server checks it. With public-key authentication the server holds just a public key and verifies a signature, so nothing reusable reaches it.

solid answer

~50 s

In the `password` method (RFC 4252 section 8) the client puts the password itself inside an `SSH_MSG_USERAUTH_REQUEST`. The transport encrypts the packet, but the server decrypts it and compares it with its password database, usually through PAM. So the server, or an impostor you reached after accepting a wrong host key, learns a secret that works again, here and anywhere it was reused, and that can be guessed. In the `publickey` method (section 7) the server keeps only the public key, for example a line in `~/.ssh/authorized_keys`, and the client proves it holds the matching private key by signing data that includes this connection's session identifier. The private key and its passphrase never leave the client, and a stolen `authorized_keys` file or a recorded signature lets nobody in. RFC 4252 makes `publickey` the only method every implementation must support.

go deeper

for a junior

Recall the two shapes: a password login sends a reusable secret the server checks, while a key login sends a signature only the private-key holder can make, and the server keeps just the public half.

for a middle

Explain the packets: a request carrying the password versus one carrying a signature over the session identifier, and why transport encryption protects the wire but not the endpoint that decrypts it.

for a senior

Show who learns what when a server is compromised or impersonated: an accepted wrong host key turns a password login into a captured credential, while a key login leaves only a signature no other connection accepts.

for a principal

Frame the trade: keys remove a guessable, relayable secret but move risk to client endpoints and key lifecycle, which is why teams add passphrases, hardware-backed keys or short-lived certificates.

## Two methods, two different things on the wire SSH user authentication (RFC 4252) runs after the transport layer has finished its key exchange, so every authentication packet already travels **encrypted and integrity-protected**. What differs between methods is what the client puts inside the `SSH_MSG_USERAUTH_REQUEST`, and what the server must hold to judge it. 1. **`password` (RFC 4252 section 8).** The request carries the user name, the method name `"password"` and the password itself in UTF-8. The RFC calls it *plaintext* because the client neither hashes nor challenges it; the transport's encryption is all that hides it on the wire. The server decrypts the packet and compares the password with its account database, which on a Linux host usually means PAM and a stored password hash. 2. **`publickey` (RFC 4252 section 7).** The request carries the public key and a **signature** made with the matching private key over data that includes this connection's **session identifier**. The server checks that the key is authorised for the account and that the signature verifies. RFC 4252 makes `publickey` the only method every implementation **must** support; `password` is one implementations **should** support. ## What each side has to keep | | Password login | Public-key login | |---|---|---| | Client holds | the password, remembered or in a password manager | the private key file, usually passphrase-encrypted | | Sent to the server | the password itself, inside the encrypted transport | the public key and a signature | | Server stores | a verifier for the password, such as a hash | the public key, e.g. one line in `~/.ssh/authorized_keys` | | Reusable if captured | yes, on this server and wherever it was reused | no, the signature is bound to one connection | | Open to online guessing | yes, by repeated attempts | not in practice, with a modern key | ## What a compromised or impersonated server learns RFC 4251 section 9.4.5 states the weakness plainly: the password mechanism **assumes the server has not been compromised**. If it has, every user who logs in hands the attacker a valid user name and password. The same happens with an **impostor**. A user who accepts a host key they should have rejected has completed the key exchange with someone else, and that party decrypts the password exactly as the real server would, then can use it against the real one. A public-key login gives that same server much less: - the **public key**, which was never secret; - a **signature over that connection's session identifier**, which no other connection accepts, because each connection derives its own identifier; - the fact that the client holds the private key, but not the key itself. The same section of RFC 4251 puts it in one line: public key authentication makes no assumptions about security on the server. Section 9.4.4 adds the other half: it does assume the **client host** has not been compromised. ## Where the passphrase fits A private key file is normally encrypted with a **passphrase**. The passphrase is used only on the client, to decrypt the key before it signs, and it is never part of any SSH message. So: - a strong passphrase protects against someone who **copies the key file** from a disk or a backup; - it does nothing for, and nothing against, the server, which never sees it; - an unencrypted key file is a bearer credential: whoever copies it can log in wherever the public key is authorised, until that public key is removed. Generating and installing keys, and the permissions sshd insists on for the `.ssh` directory, belong to the material on running OpenSSH on one host. Keeping a decrypted key in memory and lending it to other hosts belongs to the material on the SSH agent. ## What a key login does not fix Moving from passwords to keys changes where the risk sits rather than removing it: - **The client endpoint becomes the target.** Malware on a laptop can use a key that is already unlocked; hardware-backed FIDO keys and short-lived certificates narrow that window. - **Key lifecycle.** A public key in an `authorized_keys` file keeps working for as long as it stays there. Removing a departed user's keys is a process problem, which is one reason organisations move to CA-signed user certificates that expire. - **Host-key checking still matters.** It no longer protects a password, but accepting a wrong host key still means your commands, output and files pass through an impostor. ## The short version A password login sends a reusable secret to whoever is at the other end. A key login sends a proof that works only for that one connection, and the secret never leaves the client.

  • Is an SSH password sent across the network in clear text?
    No. RFC 4252 calls the field plaintext because it is not hashed or challenged, but the whole request travels inside the transport layer's encryption, which is negotiated before user authentication starts. The RFC even says password authentication SHOULD be disabled if the transport offers no confidentiality. The exposure is at the endpoint: whichever server finished the key exchange with you decrypts the password.
  • Does an SSH key's passphrase protect you if the server you log in to is compromised?
    It is irrelevant there: the passphrase only decrypts the private key file on the client and is never sent. What protects you is that the server only ever receives the public key and a signature bound to that connection. The passphrase guards a different threat, someone copying the key file from your disk or a backup.

  • The SSH password travels across the network in clear text.
  • With key login the server keeps a copy of the user's private key.
  • The key's passphrase is sent to the server to unlock the login.
  • A recorded key-login signature can be replayed later to log in again.
  • An unencrypted private key file is harmless if someone copies it.
open as a page

In SSH's publickey authentication method, what does the client sign, and why can't that signature be replayed to log in on another connection?

level: middleimportance: must knowfreq 38%

basics

~20 s

The client signs the session identifier, the exchange hash of that connection's first key exchange, followed by the user name, service, method, algorithm and public key. Each connection has its own session identifier, so the signature verifies only where it was made.

open as a page

In OpenSSH's authorized_keys file, how do the command=, no-pty and expiry-time= options limit what one key can do on a shell host?

level: middleimportance: should knowfreq 26%

basics

~20 s

Options written before a key in authorized_keys apply only to logins made with that key: command= runs a fixed command instead of whatever the client asked for, no-pty refuses a terminal, and expiry-time= makes sshd refuse the key after a date.

open as a page

With OpenSSH's sshd, how does AuthenticationMethods publickey,keyboard-interactive require both a key and a one-time code, and why keyboard-interactive rather than password?

level: seniorimportance: should knowfreq 14%

basics

~20 s

AuthenticationMethods publickey,keyboard-interactive makes sshd accept a valid key first, answer it with partial success, then require a keyboard-interactive round. Keyboard-interactive (RFC 4256) carries prompts the server chooses, so a PAM module can ask for a one-time code.

open as a page

With OpenSSH user certificates, what does sshd check before accepting a CA-signed key, and how do principals map a certificate to an account?

level: seniorimportance: should knowfreq 20%

basics

~20 s

sshd accepts an OpenSSH user certificate when a trusted CA signed it, the current time is inside its validity window, a principal fits the account, its critical options are understood and allowed, and the client signs the session with the certified key.

open as a page

In OpenSSH, what does a FIDO-backed key such as [email protected] prove at login, and what do touch and verify-required add?

level: seniorimportance: nice to knowfreq 9%

basics

~20 s

A FIDO-backed SSH key signs inside a hardware authenticator, so a login proves that device was present; the file on disk is only a key handle. sshd requires a touch by default, and verify-required also demands a PIN-verified signature.

open as a page