Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
On your computer (not on the server):
ssh-keygen -t ed25519 -C "laptop-2026"
ssh-copy-id admin@192.0.2.10
ssh admin@192.0.2.10Press Enter for the default file, and give the key a passphrase.
Step by step
- Make a key pair.
ed25519is short, fast and secure (use-t rsa -b 4096only for very old systems):
ssh-keygen -t ed25519 -C "laptop-2026"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/alice/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/alice/.ssh/id_ed25519
Your public key has been saved in /home/alice/.ssh/id_ed25519.pubid_ed25519 is the private key — it never leaves your computer. id_ed25519.pub is the public key — that one goes to servers.
- Copy the public key to the server (you log in with the password one last time):
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@192.0.2.10No ssh-copy-id (Windows PowerShell, old systems)? Do the same by hand:
cat ~/.ssh/id_ed25519.pub | ssh admin@192.0.2.10 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'- Type the passphrase only once per session with the agent:
(macOS and most Linux desktops start the agent for you; Windows has the "OpenSSH Authentication Agent" service.)
- Give the server a short name in your client config:
Host web1
HostName 192.0.2.10
User admin
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesNow ssh web1, scp file web1:/tmp/ and rsync … web1: all use the key.
- When keys work for every admin, turn off password login on the server (
PasswordAuthentication no) — see the OpenSSH guide. Keep a second session open while you change it.
Check that it worked
Force key-only login — if this works, the key is used:
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Still asks for the password | The key is not in authorized_keys, or file rights are too open. | On the server: chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys; owner must be the user. |
Permission denied (publickey) on RHEL although the key is there | SELinux label of .ssh is wrong (copied files). | restorecon -Rv ~/.ssh. |
Too many authentication failures | The agent offers many keys before the right one. | IdentitiesOnly yes and IdentityFile in ~/.ssh/config. |
UNPROTECTED PRIVATE KEY FILE! | Your private key is readable by others. | chmod 600 ~/.ssh/id_ed25519. |
| Works for your user, not for root | Root login is (correctly) not allowed. | Log in as your user and use sudo. |
no matching host key type found | Very old server or client algorithms. | Update the old side; use ed25519/rsa-sha2 keys. |
Go further
- Hardening after keys work: Install and harden the OpenSSH server. Sign Git commits with the same key: How to sign Git commits.
- Command pages: ssh-keygen, ssh-copy-id, ssh-agent, ssh.
- Learn it: RH124 — Configure and secure SSH. Previous how-to: Install and enable the SSH server.
1Which key file goes to the server, and which never leaves your computer?
The .pub file goes to the server; the private key (id_ed25519) stays on your computer.
2How do you prove that a login uses the key and not a password?
ssh -o PasswordAuthentication=no -o BatchMode=yes HOST — it only works with the key.