# SSH Public Key Authentication

> You log in by proving you hold a private key. No password is sent.

**Field:** Infrastructure  
**Category:** SSH & Remote Access  
**Also known as:** Public Key Authentication, Key-Based Login, Passwordless SSH

## Think of it like

Think of it like a secret handshake. The guard knows your half, and only you can do the rest.

## Definition

Public key authentication is logging in with a key pair, not a password. The server sends your computer a random challenge. Your computer signs it with the private key. The server checks the sign with your public key from authorized_keys. If it matches, you are in, and no secret ever crossed the network.

## Example

Emma turns on key login for her server and turns password login off. Bots guessing passwords now get nowhere.

## Example code

```console
$ ssh -v emma@203.0.113.10
debug1: Offering public key: /home/emma/.ssh/id_ed25519 ED25519
debug1: Server accepts key: /home/emma/.ssh/id_ed25519 ED25519
```

With -v, SSH shows its work. It offers the key, and the server accepts it.

## Why it matters

It cannot be guessed like a password. A stolen server log holds no secret to use again.

## Common mistake

Turning password login off before testing the key. Test the key in a second window first.

## Three principles

- **A challenge.** The server asks a fresh question.
- **Signed reply.** Only the private key can sign it.
- **Nothing to steal.** No secret goes over the line.

## Related terms

- [SSH Key Pair](https://learn.benibix.com/term/infrastructure/ssh-key-pair)
- [authorized_keys](https://learn.benibix.com/term/infrastructure/authorized-keys)
- [SSH Password Authentication](https://learn.benibix.com/term/infrastructure/ssh-password-authentication)
- [ssh-agent](https://learn.benibix.com/term/infrastructure/ssh-agent)
- [Multi-Factor Authentication (MFA)](https://learn.benibix.com/term/development/multi-factor-authentication)
- [Public-Key Cryptography](https://learn.benibix.com/term/development/public-key-cryptography)

## Taught in

- [SSH Keys and ssh-keygen](https://learn.benibix.com/learn/infrastructure-ssh/ssh-keys-and-ssh-keygen): SSH, 3/9

![A key pair made by ssh-keygen. The private key stays on the laptop in ~/.ssh/id_ed25519, locked with a passphrase, and ssh-agent holds it open for the day. A copy of the public key sits on the server in ~/.ssh/authorized_keys. At login the server sends a challenge, the laptop signs it with the private key, and the server checks the signature with the public key.](https://learn.benibix.com/diagrams/inf3-ssh-keys.svg)

---

Source: https://learn.benibix.com/term/infrastructure/public-key-authentication
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
