SSH key authentication

Also known as: SSH keys

On this page 7

SSH key authentication is a method of logging in to a remote system over the Secure Shell protocol in which the client proves its identity by signing a challenge with a private key, while the server verifies the signature against a registered public key. In identity & access management within cybersecurity, it replaces shared passwords with asymmetric cryptography, so no reusable secret ever crosses the network.

Administrators, developers and automated systems rely on SSH keys to reach servers, network devices and code repositories. The method is strong when keys are protected and inventoried, and weak when private keys are copied, left unencrypted or never removed.

How SSH key authentication proves identity

SSH key authentication works through a challenge and signature exchange defined by the SSH user authentication protocol (RFC 4252). After the encrypted transport is established, the client announces which public key it wants to use, and the server checks whether that key appears in the account’s authorized_keys file or in another configured key source.

If the key is accepted, the client signs data that includes the unique session identifier, and the server verifies the signature with the stored public key. Because the session identifier differs for every connection, a captured signature cannot be replayed against another session, and the private key itself never leaves the client.

The following table lists the components involved and the role each one plays.

ComponentLocationRole
Private keyClient, usually ~/.sshCreates the signature that proves identity
Public keyServer, authorized_keysVerifies the signature
PassphraseKnown only to the userEncrypts the private key file at rest
SSH agentClient memoryHolds decrypted keys and signs on request
Host keyServerProves the server identity to the client
known_hosts fileClientRecords trusted server host keys
Components of SSH key authentication

Key algorithms and their properties

The security of SSH keys depends on the signature algorithm and key size chosen at generation time. Modern OpenSSH defaults favor Ed25519, an elliptic curve scheme with short keys, fast signing and resistance to several implementation pitfalls that affect older algorithms.

The table compares the algorithms most often found in production environments.

AlgorithmTypical key sizeCurrent status
Ed25519256 bitsRecommended default for new keys
RSA3072 to 4096 bitsAcceptable; 2048 bits is the minimum
ECDSA256 to 521 bitsAcceptable but sensitive to weak randomness
DSA1024 bitsDeprecated and disabled in modern OpenSSH
Ed25519-SK or ECDSA-SK256 bitsHardware-backed keys on a FIDO2 token
Common SSH key algorithms

Note that RSA keys signed with the legacy SHA-1 based ssh-rsa signature are refused by recent servers, while the same key works with the rsa-sha2-256 or rsa-sha2-512 signature types. Hardware-backed security key types keep the private key inside a token and require a physical touch, which defeats silent theft of key files.

SSH keys compared with other login methods

SSH key authentication is stronger than password login because the server stores only public material, so a server breach does not expose a reusable secret. It sits alongside related methods in the same Topic, such as passkeys and MFA, which apply similar ideas to web and enterprise sign-in.

The comparison below shows where each approach fits.

MethodSecret on serverPhishing resistanceMain weakness
Password loginPassword hashLowGuessing and credential stuffing
SSH key pairPublic key onlyHighUnmanaged copies of private keys
SSH certificatesTrusted CA public keyHighRequires a certificate authority
Key plus TOTPPublic key and seedHighExtra friction for automation
FIDO2 security keyPublic key onlyVery highHardware cost and loss handling
SSH keys and alternative authentication methods

SSH certificates deserve special mention. Instead of copying each user’s public key to every server, a certificate authority signs short-lived user certificates, and servers trust the authority. This model scales better and expires access automatically.

Deploying and managing SSH keys

A sound deployment treats SSH keys as managed credentials, not personal files. Every key should have a known owner, a purpose, an approved algorithm and a defined lifetime, and it should be recorded in an inventory that security teams can audit.

The decision table below maps typical situations to recommended practice.

SituationRecommended choiceReason
Individual administratorEd25519 key with passphrase and agentStrong and convenient
Privileged production accessHardware-backed key or certificatePrevents key file theft
Large server fleetSSH certificate authorityAvoids key sprawl
CI pipeline or serviceDedicated key with forced commandLimits blast radius
Departing employeeImmediate key revocationCloses orphaned access
Choosing an SSH key strategy

Server-side hardening completes the picture. Setting PasswordAuthentication no removes the guessing surface, PermitRootLogin prohibit-password or a full root ban limits privilege, and options in authorized_keys such as from=, command= and no-port-forwarding restrict what each key may do. Regular credential rotation retires keys before compromise becomes likely.

Risks and common mistakes

Most failures of SSH key authentication come from weak key lifecycle management, not from broken cryptography. Large organizations often discover thousands of untracked keys that grant access long after their owners have left.

  • Unencrypted private keys on laptops or build servers can be copied and used immediately.
  • Key sprawl in authorized_keys files leaves orphaned access that nobody reviews.
  • Agent forwarding to untrusted hosts lets an attacker on that host use the forwarded agent.
  • Blindly accepting unknown host keys enables man-in-the-middle attacks.
  • Sharing one key among several people destroys individual accountability in logs.

A frequent misconception holds that a key pair alone equals multi-factor authentication. A key file is something you have; it becomes a second factor only when combined with a passphrase that the server cannot enforce, or with a separate verification step that the server does enforce.

Stripped to the essentials

SSH key authentication is a way to log in to a remote computer without typing a password. You create two matching keys. One stays secret on your own device, and the other is placed on the server you want to reach.

When you connect, the server sends a small puzzle that only your secret key can answer. Your device answers it, the server checks the answer with the public key, and you are let in. It is like a lock that opens only for one specific signet ring: the server keeps an impression of the ring, never the ring itself.

The key point is simple: guard the secret key with a passphrase, and remove keys that nobody needs any more.

Where it is applied

A mid-sized software company runs about 400 Linux servers across two cloud regions. An audit finds more than 1,900 public keys in authorized_keys files, about a third belonging to former staff or retired projects, and password login still enabled on 60 machines that receive constant guessing attempts.

The infrastructure team issues every engineer an Ed25519 key on a hardware security key and deploys an internal SSH certificate authority that signs user certificates valid for eight hours after single sign-on. Servers trust only the authority, password login is disabled everywhere, and automation accounts receive dedicated keys restricted with forced commands.

Within one quarter, the static authorized_keys entries drop to a few dozen service keys, failed login noise disappears from the logs, and offboarding requires no server changes because expired certificates simply stop working.