Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
Step by step
- One block per server or per group —
Hostis the short name you type;HostNameis the real address. - Patterns for groups — settings for many hosts at once:
Host *.prod.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
ProxyJump bastion-prod
Host *.lab.example.com 192.168.56.*
User alice
StrictHostKeyChecking accept-new- First match wins — for each setting, SSH uses the first value it finds. So put specific hosts at the top and
Host *(defaults) at the end. - The useful settings:
| Setting | Why |
|---|---|
IdentityFile + IdentitiesOnly yes | Use exactly this key (no "Too many authentication failures"). |
ProxyJump | Go through a bastion. |
ServerAliveInterval 60 | Keep idle sessions alive through firewalls/NAT. |
ControlMaster auto + ControlPath + ControlPersist 10m | Reuse one connection: the 2nd ssh/scp to the same host starts instantly. |
LocalForward 15432 db.internal:5432 | A tunnel every time you connect. |
Host *
ServerAliveInterval 60
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 10m- Split big configs — one file per customer or environment:
Include ~/.ssh/config.d/*.conf- See what SSH will really use for a host (all settings after matching):
Check that it worked
ssh web1 logs in without extra options, ssh -G web1 shows the right user, port, key and jump host, and with multiplexing a second ssh web1 opens instantly.
Common problems
| Problem | Cause | Fix |
|---|---|---|
Bad owner or permissions on ~/.ssh/config | The file is writable by others. | chmod 600 ~/.ssh/config. |
| A setting is ignored | An earlier block already set it (first match wins). | Move specific hosts up and Host * down; check with ssh -G. |
Too many authentication failures | The agent offers many keys. | IdentitiesOnly yes with the right IdentityFile. |
ControlPath too long | Long host names in the socket path. | ControlPath ~/.ssh/cm-%C (a short hash). |
| A stuck shared connection | The master connection hangs. | ssh -O exit web1, then connect again. |
| Ansible ignores the config | Ansible uses its own SSH args. | It reads ~/.ssh/config by default; check ansible.cfg ssh_args. |
Go further
- Command pages: ssh, scp, ssh-keygen.
- Next how-tos: Use a jump host with SSH, Open an SSH tunnel to a database, Log in with SSH keys.
- Learn it: RH124 — The SSH client config. Full guide: OpenSSH.
1Where must Host * defaults be in ~/.ssh/config, and why?
At the end — SSH takes the first value it finds for each setting.