~/.ssh/config file: short names instead of long commands
How to describe a machine once and connect with a two-word command, set the key, user, port, and keep the connection alive.
Updated August 23, 2026
Instead of ssh -i ~/.ssh/id_ed25519 -p 22 root@203.0.113.10, you can type ssh vds. You set it up once on your computer.
Where the file lives
On macOS and Linux, it's ~/.ssh/config. On Windows, C:\Users\<you>\.ssh\config (the same ~/.ssh/config path in Windows Terminal). The file may not exist — create it:
mkdir -p ~/.ssh
nano ~/.ssh/config
chmod 600 ~/.ssh/config
Permissions matter: if the file is readable by everyone, the client may refuse to read it.
Minimal entry
Host vds
HostName 203.0.113.10
User root
IdentityFile ~/.ssh/id_ed25519
Now this works:
ssh vds
Other tools pick up the short name too:
scp dump.sql vds:/root/
sftp vds
rsync -avz ./site/ vds:/var/www/site/
For copying files, see scp and rsync and SFTP.
Useful parameters
Host vds
HostName 203.0.113.10
User artem
Port 22
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ServerAliveInterval 30
ServerAliveCountMax 3
| Parameter | Why you need it |
|---|---|
IdentitiesOnly yes | The client offers only the specified key. Saves you when you have many keys and the server cuts off attempts |
ServerAliveInterval | Sends a packet every 30 seconds so the connection doesn't drop from inactivity |
Port | If you moved SSH to a non-standard port |
User | The default username for this host |
Multiple machines
Host vds-web
HostName 203.0.113.10
User root
IdentityFile ~/.ssh/id_ed25519
Host vds-db
HostName 203.0.113.20
User artem
IdentityFile ~/.ssh/id_ed25519
Host *
ServerAliveInterval 30
The Host * block sets shared settings for all entries. Order matters: the first match for each parameter wins, so keep the shared block at the bottom.
Common mistakes
- Tab indentation and trailing spaces — some clients complain about this. Use four spaces.
- A key path with backslashes on Windows — write
~/.ssh/id_ed25519. - Missing
HostName— the client will then try to connect to a host namedvdsand won't find it. - Permissions 644 on the file — set them to
600.
To check what exactly applies to a host:
ssh -G vds
ssh -v vds
The first command prints the resulting parameters, the second shows the connection progress — it tells you which key was offered.
The
configfile describes only your side. What the machine accepts is decided by its/etc/ssh/sshd_config, see SSH keys.