# ssh-keygen

> The command that makes a new SSH key pair on your computer.

**Field:** Infrastructure  
**Category:** SSH & Remote Access  
**Also known as:** ssh-keygen Command, Generate SSH Key, ssh-keygen -t ed25519

## Think of it like

Think of it like a key cutter in a shop. You ask, and it cuts you a new key and its lock.

## Definition

ssh-keygen is the command that makes a new SSH key pair. It asks where to save the keys and for a passphrase. It writes the private key and a .pub file beside it. Current OpenSSH makes an Ed25519 key by default, a short and strong kind. The same command can also remove an old line from known_hosts.

## Example

Jack gets a new laptop. He runs ssh-keygen once, sets a passphrase, and has a fresh key pair in his .ssh folder.

## Example code

```console
$ ssh-keygen -t ed25519 -C "jack@laptop"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/jack/.ssh/id_ed25519):
```

Ask for an Ed25519 key with a label. Press Enter to keep the usual place.

## Why it matters

Every key login starts here. Making a key takes a few seconds.

## Common mistake

Running it again and saying yes to overwrite. The old key is gone, and every server that trusted it locks you out.

## Three principles

- **Makes the pair.** Private file and .pub file.
- **Ed25519 by default.** Short and strong.
- **Never overwrite.** Old servers still want the old key.

## Related terms

- [SSH Key Pair](https://learn.benibix.com/term/infrastructure/ssh-key-pair)
- [SSH Key Passphrase](https://learn.benibix.com/term/infrastructure/ssh-key-passphrase)
- [authorized_keys](https://learn.benibix.com/term/infrastructure/authorized-keys)
- [known_hosts](https://learn.benibix.com/term/infrastructure/known-hosts)

## 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/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-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
