Passwordless SSH
How it works
Two facts make passwordless login work:
- Your private key never travels. Only a signature does.
- The server gives your key a fresh random challenge every time, so a captured signature is worthless afterwards.
No password is sent. Authentication uses the private key; it never leaves the client.
Connection phases
Phase 1 — Version exchange
Both sides announce their protocol version before anything is encrypted:
debug1: Local version string SSH-2.0-OpenSSH_10.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_10.6
Nothing secret: the greeting tells each side the other speaks SSH-2.
Phase 2 — Configuration is read
debug1: Reading configuration data /home/student/.ssh/config
debug1: /home/student/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
ssh reads your personal config, then the system-wide one. A ~/.ssh/config entry changes a port or identity here, before you connect.
Phase 3 — Key exchange (KEX): agreeing on a shared secret
Neither side sends the key. Both derive it from a Diffie-Hellman exchange, so an eavesdropper cannot calculate it:
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: mlkem768x25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
| Line | Meaning |
|---|---|
kex: algorithm |
The key-agreement negotiation. mlkem768x25519-sha256 is a modern, post-quantum-safe choice |
host key algorithm |
The algorithm used to sign the server’s host key — rsa-sha2-512 here |
server->client cipher |
How server-to-client traffic is encrypted |
client->server cipher |
How client-to-server traffic is encrypted |
MAC: <implicit> |
Modern AEAD ciphers such as chacha20-poly1305 include tamper detection, so a separate MAC is not added |
KEX_ECDH_REPLY |
The key exchange completed |
Both sides match their lists and pick the same cipher and same KEX. If the only shared option is disabled, the connection dies here.
Phase 4 — The server proves it is the server
debug1: Server host key: ssh-rsa SHA256:G1KiAb1IZQvs+71a8ErbhWLYxw1KaQtu2QwAIJpr/iE
debug1: checking without port identifier
debug1: load_hostkeys: fopen /home/student/.ssh/known_hosts: No such file or directory
The server presents its host key. ssh compares its fingerprint with ~/.ssh/known_hosts, which records host keys you accepted before.
On a first connection known_hosts has no entry and ssh asks you to confirm the fingerprint:
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ED25519 key fingerprint is SHA256:abcdefg.....
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Until you accept it, the connection is encrypted but the server is not authenticated to you. See SSH keys for host keys.
Phase 5 — New keys, and the session becomes encrypted
debug1: SSH2_MSG_NEWKEYS sent
debug1: Sending SSH2_MSG_EXT_INFO
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
Everything before this line was plaintext; everything after is encrypted.
rekey in after 134217728 blocks means the session key is refreshed after roughly two gigabytes, so no single key protects unbounded data.
Phase 6 — Service request
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
The server lists its login methods. publickey is present, so key login is possible. keyboard-interactive is the password prompt; password appears instead on a server using the older straight method.
Phase 7 — Offering the public key
Your public key is what gets sent.
debug1: Next authentication method: publickey
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 3 keys
debug1: Will attempt key: ~/.ssh/id_ed25519 ED25519 SHA256:GjcS0ahO... explicit
debug1: Offering public key: ~/.ssh/id_ed25519 ED25519 SHA256:GjcS0ahO... explicit
debug1: Server accepts key: ~/.ssh/id_ed25519 ED25519 SHA256:GjcS0ahO... explicit
Next authentication method: publickey— the client tries the key first, because the server listed it.agent returned 3 keys—ssh-agentholds three keys. Without it, this is your keyring. The client tries them in order.Offering public key— the public half, its algorithm (ED25519) and fingerprint. Safe to show anyone; nothing secret is in it.Server accepts key— this public key appears in this server’sauthorized_keysfile. It does not mean you are logged in.
If the key is not in authorized_keys, the offer is refused. With IdentitiesOnly=yes and no agent:
student@127.0.0.1: Permission denied (publickey,keyboard-interactive).
That line is the whole diagnosis: the offered key is not on the server’s list, and password login was not attempted.
Phase 8 — The signature exchange
The debug output hides this part: it happens over encrypted bytes, inside the client library’s auth loop. The two sides do this:
- The server, having accepted the public key, sends back a challenge: a session identifier plus a random nonce that must be signed.
- The client signs the challenge with the private key. Ed25519 signing takes a few dozen microseconds, so
ssh -vshows no dedicated line at default verbosity. - The server verifies the signature against the public key it had on file.
- On success, the server considers you authenticated as that user.
The signature is bound to the session identifier, so one captured in a connection cannot be replayed into another. That freshness makes passwordless login safe.
Phase 9 — The session channel
debug1: channel 0: new session [client-session] (inactive timeout: 0.000000)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: Remote: /home/student/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Sending command: echo REMOTE_LOGIN_OK
debug1: Entering interactive session.
debug1: Exit status 0
channel 0: new session— authentication’s result: a multiplexed data channel. It later carries your shell, a forwarded port, or a Git transfer.Remote: ... key options: agent-forwarding port-forwarding ...— the server’sauthorized_keysentry may carry extra permissions. The server lists what it allows for this key.Sending command: echo REMOTE_LOGIN_OK— the command line, over the encrypted channel.Exit status 0— success, from the remote command.
Phase summary
| # | Phase | What happens |
|---|---|---|
| 1 | Banner | Both sides announce SSH-2 |
| 2 | Config | ~/.ssh/config and /etc/ssh/ssh_config are read |
| 3 | KEX | Shared secret derived; cipher agreed |
| 4 | Host key | Server’s identity checked against known_hosts |
| 5 | NEWKEYS | Traffic becomes encrypted |
| 6 | Service | Server lists available auth methods |
| 7 | Offer | Client offers the public key; server finds it in authorized_keys |
| 8 | Sign | Client signs a challenge with the private key; server verifies |
| 9 | Session | Channel opened; your shell or command runs |
Reproduce the trace
ssh-keygen -t ed25519 -N '' -f /tmp/demo
mkdir -p ~/.ssh && cat /tmp/demo.pub >> ~/.ssh/authorized_keys
ssh -v -i /tmp/demo localhost 'echo it worked'
Increasing verbosity
-v prints the first level of detail. Problems go deeper:
ssh -v— the phases and the offered keys. Enough for “the server refuses my key”.ssh -vv— configuration subtleties, agent responses, cipher details.ssh -vvv— near-everything, including raw packet internals. Use it when the problem is inside the key exchange; expect long output.
Check yourself — 4 questions
1. In the ssh -v output, at which line does the session become encrypted?
At SSH2_MSG_NEWKEYS received (Phase 5). Everything before it was plaintext; everything after is encrypted.
2. Server accepts key appears in ssh -v. Does that mean you are logged in?
No. It only means the offered public key is present in the server's authorized_keys. The proof — signing the challenge — happens next, and it is silent even at -v.
3. Permission denied with only (publickey,keyboard-interactive) listed. What is the diagnosis?
The offered key is not in the server's authorized_keys (and password login was not used). Fix it by installing the public key — ssh-copy-id — not by copying the private one.
4. What exactly does your client send in Phase 7 — and what in Phase 8?
Phase 7: the public key. Phase 8: a signature over a fresh challenge, made with the private key. The private key itself never leaves the machine in either phase.