What is SSH Key Authentication?

SSH key authentication is a way to prove control of an authorised cryptographic key when connecting to a remote system using Secure Shell (SSH). The client uses a private key to create a digital signature, and the server checks that signature against an authorised public key for the requested account.
The private key is not sent to the server during authentication. A successful key check may grant access, or the server may require another authentication method and apply additional restrictions. SSH also separately checks the server's identity using its host key.
How does SSH key authentication work?
A user or administrator creates a key pair: a private key that must be protected and a corresponding public key that can be installed on a server or registered with a service. The server records which public keys are allowed for an account. When the client connects, it proves it can use the private key by signing authentication data associated with that SSH session.
The server checks that the public key is authorised for the requested account and that the signature is valid. A valid signature proves control of the private key at that moment; it does not prove that the person operating the client is the intended owner if the key or client has been compromised.
The illustration shows a simplified flow: create a key pair, authorise the public key, sign session data on the client, verify the signature and apply the server's access rules.

RFC 4252, section 7, defines SSH public key authentication. The signed data includes the session identifier and authentication request details. A client may first ask whether a public key would be acceptable, but that preliminary check does not itself prove possession of the private key.
Private key, public key and host key
Item | Purpose | Where it belongs |
|---|---|---|
User private key | Creates signatures to authenticate the user or client | Protected on the client or in a supported hardware authenticator |
User public key | Lets the server check signatures and decide whether that key is authorised | Registered with the server or trusted identity system |
Server host key | Helps the client recognise the SSH server | The server protects its private host key; clients verify the public host key or a trusted certificate |
Session keys | Protect traffic during a particular connection | Derived during SSH key exchange; distinct from the long-term user and host keys |
A public key is designed to be shared, but its placement matters: adding it to an account's authorised keys can grant access to the holder of the corresponding private key. Never upload a private key when a service requests a public key.
An SSH key is one kind of credential. The authentication check and the permissions granted afterwards are connected but separate decisions, as explained in our access control guide.
Why verify the server's host key?
Before sending user authentication, the SSH client negotiates a protected connection and checks the server's host identity. OpenSSH commonly stores known host keys in a known_hosts file. On a first connection, compare the displayed host key fingerprint with a value obtained through a trusted independent channel, such as the provider's verified console or administrator.
A changed host key can be legitimate after a server rebuild, but it can also indicate a connection to the wrong system or an interception attempt. Stop and verify the change independently before accepting it. Do not routinely delete the saved key or disable host checking just to make the warning disappear.
The OpenSSH client manual describes host key checking and the files involved. Host key verification identifies the server; a user's public key authenticates the client account. Neither check replaces the other.
How are public keys authorised?
A common OpenSSH setup stores authorised user public keys in the target account's ~/.ssh/authorized_keys file. Each entry can include restrictions, and the server's configuration determines which file or other source it uses. Some organisations use a central command, certificates signed by a trusted SSH certificate authority, or a hosting provider's control panel instead.
The OpenSSH server configuration manual describes authorised key files, alternative lookup commands and revocation settings. A public key's presence in one file is not enough if the server is configured to consult a different source or deny the account.
SSH certificates are distinct from a web TLS certificate. An SSH user certificate can carry an identity, principals, validity period and restrictions, and is checked against a trusted signing authority. Its actual validity and access depend on the server's configuration.
How to set up an SSH key safely
The following is an illustrative OpenSSH workflow for a system you are authorised to administer. Commands and available tools differ by operating system, provider and version. Keep an existing working session or another tested recovery route before changing access settings.
Generate a new Ed25519 key pair with ssh-keygen -t ed25519, if the client and server support it. Choose a new file name if a key already exists; do not overwrite an existing key unintentionally.
Set a strong passphrase when prompted to protect the private key at rest. Record the recovery arrangement securely; losing the private key or its passphrase may prevent its use.
Register only the resulting public key, normally the file ending in .pub, with the correct remote account using the provider's approved process.
Verify the server's host key fingerprint through a trusted independent source. Connect with ssh -i PATH_TO_PRIVATE_KEY USER@HOST, substituting the real values.
Confirm that key authentication succeeds in a separate session before changing password authentication or firewall rules. Check effective server configuration and any required additional authentication.
The OpenSSH ssh-keygen manual documents supported key types and options. Ed25519 is a common choice, but compatibility, organisational policy or hardware support may require another supported algorithm. Do not weaken a service's policy merely to make an outdated client connect.
On typical Unix-like OpenSSH installations the account's home directory and SSH files must not be writable by unauthorised users. Incorrect ownership or permissions can cause the server to ignore an authorised key. Exact checks depend on configuration and platform; consult the server logs and documentation before changing permissions.
What is an SSH key passphrase?
A passphrase can encrypt a private key file at rest. The user enters it locally to unlock the key for use; it is not normally sent to the server as the account password. A passphrase reduces the value of a stolen key file, but it does not protect an already unlocked key from a compromised client.
An SSH agent can hold identities and perform signing operations on request so the passphrase need not be entered for every connection. Protect access to the agent as well as the key file. Forwarding an agent to a remote machine can expose its signing capability to a sufficiently privileged attacker on that machine, even though the private key itself is not copied there. Use forwarding only where necessary and trusted.
Is SSH key authentication safer than a password?
A properly generated, protected key avoids sending a reusable account password to the server and resists ordinary password guessing against that key. However, the practical outcome depends on private key protection, verified host identity, server configuration, access restrictions and recovery. A stolen unencrypted key, compromised agent or overprivileged account can still give an attacker access.
A local passphrase and an SSH key are not automatically multi-factor authentication in every implementation. Whether a setup meets a particular assurance requirement depends on how the factors are enforced, where the private key is held and the applicable policy. A hardware security key with user verification can provide different protections from a key file on a laptop.
A service may accept both passwords and keys. Adding a key does not automatically disable password sign-in. Before disabling a method, confirm a working alternative and recovery route, and consider any other configured methods or account requirements.
SSH keys and broadband connections
Imagine a UK network administrator accessing a server from home over broadband. The SSH client connects through the home router and ISP to the server's address and SSH port. A stable connection helps the session stay usable, but key authentication itself does not increase broadband speed or change the connection's bandwidth.
Symptom | Likely layer to investigate | Useful next check |
|---|---|---|
Hostname cannot be resolved | DNS or the supplied name | Check the name and resolver separately |
Connection times out | Network path or filtering | Check server address, port, firewall and reachability |
Host key warning | Server identity | Verify the fingerprint through a trusted channel |
Permission denied for publickey | User authentication or authorisation | Check user, offered key, authorised key source and server logs |
Sign-in works but a command is denied | Account permissions or restrictions | Check the account's privileges and key restrictions |
These are diagnostic clues, not guarantees. For instance, a firewall can reject a connection immediately rather than timing out, and a server may hide details in its error messages. Our authentication guide explains the wider identity check.
Why does SSH key authentication fail?
Start by separating a network failure from a rejected authentication. If the server cannot be reached, changing keys will not repair the network path. If SSH reports a public key rejection, check these points in order:
Confirm the correct username, host, port and server host fingerprint.
Check which identity the client offers. OpenSSH's ssh -v option provides diagnostic messages; redact sensitive details before sharing logs.
Confirm the matching public key is authorised for that account in the source the server actually uses.
Check file ownership and permissions, public key algorithm compatibility, account restrictions and relevant server logs.
Check whether the server requires another authentication method or applies certificate, source address or key restrictions.
Confirm the key is available and unlocked, and that an agent or hardware authenticator is functioning as intended.
Do not share a private key, passphrase or complete sensitive logs with support. A successful signature can still be followed by a refusal under account or server policy.
What happens if a private key is lost or exposed?
If exposure is suspected, remove or revoke the corresponding public key wherever it grants access, following the system's incident process. Review related accounts, logs, automated jobs and other locations where the key was authorised. Generate a replacement key pair on a trusted device and register the new public key through a trusted route.
Changing a key file's passphrase does not change its underlying public key and does not revoke access for someone who already obtained usable private key material. Removing a public key or revoking a certificate generally affects new authentication attempts; it does not necessarily terminate sessions that are already active. Review and end affected sessions separately where appropriate.
If the key is lost but not exposed, use the provider's recovery process or a separately authorised administrator. Do not leave an obsolete key authorised simply because its owner no longer has a copy.
Frequently asked questions
Does SSH send the private key to the server?
No. In public key authentication, the client signs authentication data with the private key and sends the signature; the server checks it using the public key.
Is an SSH key the same as a password?
No. An SSH key uses a public and private cryptographic key pair. A password is a shared secret used by a different authentication method. A private key can itself be protected by a local passphrase.
Can I use the same SSH key on several servers?
Yes, if each server authorises its public key. However, compromise then affects every server that trusts it. Separate keys can make access tracking and revocation easier.
What is the authorized_keys file?
It is a common OpenSSH file listing public keys permitted for an account. Its location and use depend on server configuration, and other authorisation methods may also be used.
Does removing a public key end active sessions?
Not necessarily. Removing or revoking a key normally prevents future authentication using it, but active sessions may need to be identified and terminated separately.
What does a host key warning mean?
The server identity presented to the client is unknown or differs from the stored expectation. Verify the fingerprint through a trusted independent channel before proceeding.
Can SSH key authentication work without a passphrase?
Yes, a private key file can be created without one, but a stolen unencrypted key file is easier to misuse. Use protection appropriate to the device, automation and security policy.
Key takeaway
SSH key authentication proves control of an authorised private key through a signature tied to the connection. Protect the private key, verify the server's host identity, limit account permissions and maintain a tested way to revoke or replace access.

