webvaltas

SSH keys — private and public

Remote login crosses machines you do not control. Packets can be read and rewritten on the path.

What SSH verifies

SSH answers three questions:

Question Answer
Is this computer who it says it is? The host key
Is this user who they say they are? Authentication — passwords or a key pair
Can anyone read or change what we send? Encryption of the session

The first two use key pairs.

Key pairs

An SSH key pair is one lock. Both halves derive from the same random number:

  • The private key is the secret and never leaves your computer. It produces proof of identity.
  • The public key is not secret. You hand copies to servers. It verifies the proof; it cannot create it.

Knowledge of the public key lets you check a signature. It never lets you forge one.

Padlock comparison

  • The private key is the key to a padlock.
  • The public key is the padlock itself, which anyone may hold.

Anyone holding the padlock can lock a box against your key; only you can open it. Encryption uses this direction. SSH login does not: the server sends a challenge, and the client signs it. The one-way property is the same; the arrows are reversed.

Signing a challenge

  1. The server makes up a random challenge, a throwaway phrase.
  2. Your computer signs it with the private key.
  3. The server verifies the signature against the public key on file.
  4. If it checks out, the server knows that whoever holds that private key is present, with no password.

Nothing secret crosses the wire except the signature, and that signature is useless on a different challenge.

LaptopServer 1. challenge2. signature

Private and public keys

Private key Public key
Symbol ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
Who holds it Only you, always Every server you log into
Can it be shared? Never Yes, freely; it is meant to be distributed
If it leaks Whoever has it is you; rotate immediately Nothing bad happens; it is public by design
What it can do Produce signatures Verify signatures
Permissions on disk 600 — strict 644 — conventional

Readable public key permissions are not a security problem: there is nothing in the file to steal.

What the public key contains

It is not a hashed password. It is a number derived from your private key, written as text:

text
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEwD0Q0Z0XKZo7w1Ny2f6jZv1R7lT2vQx9Qz
0jYjJ0nHk you@example.vnce.eu

Three parts:

  • ssh-ed25519 — the algorithm this key uses.
  • The long base64 blob — the public key material.
  • A trailing comment — free-form text, usually you@example.vnce.eu. Some tools parse it; it has no security meaning and you can edit it.

A key pasted into the wrong file, or with a truncated base64 chunk, is not recognised and the login fails without a useful message. Copy the entire single line.

Fingerprints

A key has a short digest, the fingerprint. Use it to refer to the key:

bash
ssh-keygen -lf ~/.ssh/id_ed25519.pub
text
256 SHA256:GjcS0ahO2DorL/ncaZOCi47Ra2iw8bBkttQz7nTXVNk you@example.vnce.eu (ED25519)
  • Confirming a downloaded key is the key you meant to get, where you cannot open the file safely.
  • Comparing the new fingerprint in a host key warning. Do not accept the new key until you know why it changed.

Two kinds of key pairs

SSH uses key pairs for two unrelated jobs:

Kind Held by Purpose
User key Your laptop Proves the person is allowed to log in
Host key The server Proves the server is the one you first connected to

The host key shows in the Server host key: line: same mathematics, different job.

Generate a key pair

bash
ssh-keygen -t ed25519 -C "you@example.vnce.eu"

Accept the default file location. At the passphrase prompt you may press Enter twice to leave it empty. A passphrase makes a stolen laptop survivable — see key passphrase.

Two files:

  • ~/.ssh/id_ed25519 — private. chmod 600. Never copy it anywhere.
  • ~/.ssh/id_ed25519.pub — public. This one you paste on servers.

How passwordless SSH works, step by step

Check yourself — 3 questions

1. The server has your private key in its authorized_keys and login still fails. What was pasted in the wrong place?

The public key belongs in authorized_keys. The private key never leaves your machine.

2. An attacker records your signature as it travels. Can they log in with it next week?

No. Each challenge is random; a recorded signature only covers that one challenge.

3. Your public key file has permissions 644; your private key has 600. Which is a security mistake?

Neither. Public keys are meant to be readable. Only the private key needs 600.