What is ~/.ssh/config?
It is a plain text file read by the OpenSSH client every time you run ssh, scp, sftp or rsync over SSH. It maps names you choose to real addresses and options, so ssh fra-db can mean "connect to 203.0.113.61 on port 2207 as user ops with this key, through that bastion". A system-wide version lives at /etc/ssh/ssh_config, but personal settings belong in your own file. Create it with safe permissions:
install -m 700 -d ~/.ssh touch ~/.ssh/config && chmod 600 ~/.ssh/config
The client refuses to use a config file that other users can write, so keep the mode at 600.
What does a host entry look like?
Host chi-web
HostName 203.0.113.25
User ops
Port 2207
IdentityFile ~/.ssh/ops_ed25519
IdentitiesOnly yes
Host ams-backup
HostName 198.51.100.12
User mirror
IdentityFile ~/.ssh/mirror_ed25519
Now ssh chi-web, scp report.csv chi-web:/tmp/ and rsync -a site/ chi-web:/srv/site/ all use the right address, port, user and key. IdentitiesOnly yes makes the client offer only the named key instead of every key in your agent, which avoids "Too many authentication failures" on servers with a low MaxAuthTries.
In what order are settings applied?
First match wins, per option. The client reads the file top to bottom and keeps the first value it finds for each option among the blocks that match the host. So put specific hosts first and the catch-all Host * block last; a Host * at the top would override everything below it. You can check the final result for any alias:
ssh -G chi-web | grep -E '^(hostname|user|port|identityfile|proxyjump) '
Which patterns and keywords help most?
| Keyword | What it does | Example value |
|---|---|---|
Host with wildcards | Matches many names | Host *-db sea-* |
ProxyJump | Connects through a bastion | bastion-ash |
ServerAliveInterval | Sends keepalives | 40 |
LocalForward | Opens a tunnel on connect | 8006 127.0.0.1:8006 |
Include | Pulls in other files | ~/.ssh/config.d/*.conf |
Match | Conditional blocks | Match host 10.* exec "test -f ~/.vpn-up" |
The LocalForward line in the table is a neat trick for a Proxmox host: connecting opens the web interface at https://localhost:8006 on your computer, while port 8006 on the machine stays firewalled from the world.
How do I reuse one connection for many sessions?
Connection sharing makes the second and later connections to a host nearly instant, which speeds up Ansible runs, Git operations and repeated scp calls:
Host *
ControlMaster auto
ControlPath ~/.ssh/cm-%C
ControlPersist 10m
ServerAliveInterval 40
ServerAliveCountMax 3
HashKnownHosts yes
%C is a hash of the connection details, which keeps socket paths short. ssh -O check chi-web shows whether a master is running and ssh -O exit chi-web closes it. Put this block at the end of the file, after all specific hosts.
How should I organize many machines?
Split them by project or city with Include. Place Include ~/.ssh/config.d/*.conf at the very top of the main file, then keep files such as config.d/shop.conf and config.d/lab.conf. Naming hosts by city and role, such as sgp-cache1 or phx-build, makes it obvious where a command lands. With identical prices in every city, many teams spread machines widely, and clear names prevent mix-ups.
Is there anything I should not put in the config?
- Avoid
StrictHostKeyChecking noon real servers; it silently accepts changed host keys.accept-newis the safer choice for new hosts. - Avoid
ForwardAgent yesinHost *; enable it only for hosts you fully trust, or useProxyJumpinstead. - Never store passwords; the format has no field for them on purpose.
After a machine is reinstalled from the panel, its host key changes. Run ssh-keygen -R with the address, connect once and confirm the new fingerprint.
Keep Reading
Everyday SSH commands
The SSH toolkit you will actually use on a server: ssh, ssh-keygen, ssh-copy-id, ssh-agent, scp, sftp, ssh-keyscan and tunnels.
OpenLog in with an SSH key
Create an ed25519 key, install it on your machine through the panel or ssh-copy-id, and log in without typing the root password.
OpenChange the SSH port
Move sshd off port 22 on Ubuntu, Debian, Rocky, AlmaLinux and FreeBSD without locking yourself out of the machine.
OpenProxmox VE
Proxmox VE 8 turns an x86 machine into a virtualization host with a web console for VMs and containers.
OpenFAQ
Quick Answers
Your personal file is ~/.ssh/config; the system-wide default is /etc/ssh/ssh_config.
The first value found for each option wins, so put specific hosts first and Host * last.
Run ssh -G with the alias. It prints every option the client will use.
Yes. Both go through the ssh client, so aliases, ports and keys apply automatically.
600, owned by you. The client refuses files that others can write.