# SSH Keys and ssh-keygen

> How an SSH key pair works: a private key that stays on your laptop and a public key that goes to the server. How to make one and put it in place.

**Course:** [SSH Keys and Logins](https://learn.benibix.com/learn/infrastructure-ssh)  
**Time:** 13 min

**After this lesson you can:**

- Make a key pair with ssh-keygen
- Copy the public key to a server
- Explain why the private key never leaves your laptop

## How a key pair replaces your password

An SSH key pair is two matching keys made together. The private key stays on your laptop and is never shared. The public key goes on the server, in a file called authorized_keys. When you log in, the server sends a challenge, and only the private key can sign it. No password crosses the line at all.

You make the pair with ssh-keygen. ssh-keygen -t ed25519 makes the modern kind. It writes two files in your .ssh folder: id_ed25519, the private key, and id_ed25519.pub, the public one. The public key is a single line of about 80 letters, starting with ssh-ed25519.

Next, the public key has to reach the server. ssh-copy-id does it in one line. It logs in once with your password and adds your public key to the end of authorized_keys. From then on, ssh uses the key.

This way of logging in is called public key authentication. The server checks the signature with the public key it already holds. Anyone can see the public key without harm. It can check a signature, but it cannot make one.

authorized_keys can hold many lines, one per key. Each laptop you own can have its own pair. If one laptop is lost, you delete only its line, and the others keep working.

sshd is fussy about who may touch these files. If your .ssh folder or authorized_keys can be changed by other users, it ignores them and asks for a password. chmod 700 on the folder and chmod 600 on the file fix that.

A common mistake is to send someone your private key so they can log in. Anyone who holds it is you, as far as the server knows. Ask them for their public key instead, and add it as a new line.

```console
$ ssh-keygen -t ed25519 -C "jack@laptop"
Generating public/private ed25519 key pair.
$ ssh-copy-id jack@203.0.113.10
Number of key(s) added: 1
$ ssh jack@203.0.113.10
jack@web1:~$
```
Make the pair, copy the public half to the server, and log in with no password.

![A laptop on the left holds the private key id_ed25519, locked with a passphrase and held open by ssh-agent. It was made by ssh-keygen with its copy id_ed25519.pub. A server on the right holds ~/.ssh/authorized_keys, one line with the public key. Arrows show 1, a challenge from the server, and 2, the signed reply. The server checks the signature with the public key. A note says the private key never crosses the line.](https://learn.benibix.com/diagrams/inf3-ssh-keys.svg)

### Example: Emma gives Jack access

Emma wants Jack to log in to her server. Jack offers to send her his password, and she says no.

She asks for his id_ed25519.pub instead. She pastes the one line into authorized_keys for his user. A minute later, Jack logs in with his key, and his private key never left his laptop.

**Words in this lesson:** [SSH Key Pair](https://learn.benibix.com/term/infrastructure/ssh-key-pair), [ssh-keygen](https://learn.benibix.com/term/infrastructure/ssh-keygen), [authorized_keys](https://learn.benibix.com/term/infrastructure/authorized-keys), [SSH Public Key Authentication](https://learn.benibix.com/term/infrastructure/public-key-authentication), [chmod](https://learn.benibix.com/term/infrastructure/chmod)

**Question:** Which half of a key pair goes on the server?

**Answer:** The public key. The public key goes in authorized_keys on the server. The private key stays on your laptop, because whoever holds it can log in as you.

---

Source: https://learn.benibix.com/learn/infrastructure-ssh/ssh-keys-and-ssh-keygen
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-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
