Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
ssh-keygen makes a key pair: a private key (keep it secret) and a public key (.pub, you copy it to servers). The default type today is ed25519: small, fast and secure. RSA keys should be at least 3072 bits.
It also does key housekeeping: show the fingerprint of a key, add or change a passphrase, remove an old host key from known_hosts, and sign keys with a certificate authority.
Zo schrijf je het
ssh-keygen [-q] [-t TYPE] [-b BITS] [-C COMMENT] [-f FILE] [-N PASSPHRASE]
ssh-keygen -p [-f FILE]
ssh-keygen -l [-v] [-E HASH] -f FILE
ssh-keygen -R HOSTNAME [-f KNOWN_HOSTS]
ssh-keygen -F HOSTNAME [-f KNOWN_HOSTS]
ssh-keygen -s CA_KEY -I ID [-h] [-n PRINCIPALS] [-V VALIDITY] PUBKEYOpties 42
Meest gebruikt
Make keys
Look at and change keys
known_hosts
Certificates and revocation
Signing files and other
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1Make a modern key pair
ssh-keygen -t ed25519 -C "student@server1"Press Enter for the default file. Type a passphrase (recommended for people).
2Make a key without passphrase for automation
ssh-keygen -t ed25519 -N "" -f ~/.ssh/backup_job -C "backup job server1"For cron jobs and CI. Protect the file and limit the key on the server.
3Make an RSA key for old systems
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_legacyOnly when a device does not support ed25519.
4Show the fingerprint of a key
ssh-keygen -lf ~/.ssh/id_ed25519.pub 256 SHA256:Xh7… student@server1 (ED25519)Compare fingerprints when you check which key is allowed on a server.
5Add or change a passphrase
ssh-keygen -p -f ~/.ssh/id_ed25519The key stays the same; only its protection changes. No change needed on servers.
6Remove an old host key after a server reinstall
ssh-keygen -R server2Removes server2 from ~/.ssh/known_hosts. Verify the new key before you connect again.
7Check a server's host key fingerprint on the server itself
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pubCompare with the fingerprint your client shows at the first connect.
8Get the public key back from a private key
ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pubWhen the .pub file is lost.
9Find a host in known_hosts
ssh-keygen -F server2Shows if (and which) key you trust for server2.
10Recreate missing host keys on a server
ssh-keygen -A systemctl restart sshdNeeded after a VM template was cleaned of its host keys.
11Sign a user key with your CA (short-lived access)
ssh-keygen -s ~/ca/user_ca -I alice-oncall -n alice -V +8h alice.pubServers that trust the CA accept alice for 8 hours, without editing authorized_keys.
12Sign a git commit file with an SSH key
ssh-keygen -Y sign -f ~/.ssh/id_ed25519 -n file release.tar.gzMakes release.tar.gz.sig. Others verify it with
-Y verify.
Niets past bij dit filter.
Let op
- Never copy or send the private key (the file without .pub).
- Private key files must be mode 600; otherwise ssh refuses to use them.
- DSA keys are disabled in new OpenSSH versions. Use ed25519.
Bestanden
~/.ssh/id_ed25519, ~/.ssh/id_ed25519.pub- Default user key pair.
~/.ssh/known_hosts- Trusted host keys.
/etc/ssh/ssh_host_*_key- The host keys of the server.
Tips om te onthouden
ssh-keygen -t ed25519→ssh-copy-id host→ssh host.-lfingerprint,-ppassphrase,-Rforget a host.