# The SSH Config File

> How ~/.ssh/config turns a long ssh command into a short name. How to set the user, address, port and key once for each server you use.

**Course:** [SSH Keys and Logins](https://learn.benibix.com/learn/infrastructure-ssh)  
**Time:** 10 min

**After this lesson you can:**

- Write a Host block in ~/.ssh/config
- Log in with a short name
- Know which tools read the same file

## How to stop typing the same long command

The SSH config file, ~/.ssh/config on your laptop, gives each server a short name. Under the name you write its address, your user, the port and the key to use. Then ssh shop does the same as ssh -p 2222 -i ~/.ssh/id_ed25519 lucy@203.0.113.10. The file is plain text, and you can write it by hand.

Each server gets a block that starts with Host and the short name. The lines under it are indented. HostName is the real address. User is your user name there. Port is only needed if it is not 22. IdentityFile points at the key.

The short name works for more than ssh. scp, sftp and rsync read the same file. So rsync -av site/ shop:/var/www/ copies to the right server, as the right user, with the right key.

A Host line can also match many names at once. Host * applies to every server, so it is the place for settings you want everywhere. Put it at the end of the file.

For each setting, ssh uses the first value it finds and ignores later ones. So a specific block must come before Host *. If a setting seems to be ignored, look for an earlier block that matched first.

This file is your own, on your laptop. It changes nothing on any server. The file that sets rules for the server itself is a different one, with a similar name, and it lives on the server.

A common mistake is to put a password in the config file. There is no setting for it, on purpose. Use a key, and let the agent hold it.

```console
$ cat ~/.ssh/config
Host shop
    HostName 203.0.113.10
    User lucy
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
$ ssh shop
lucy@shop:~$
```
One block in the config file, and the long command becomes two words.

![On the left, the file ~/.ssh/config on your laptop holds a block: Host shop, HostName 203.0.113.10, User lucy, Port 2222 and IdentityFile ~/.ssh/id_ed25519. An arrow leads to what you type, $ ssh shop, and below it to what ssh runs: ssh -p 2222 -i ~/.ssh/id_ed25519 lucy@203.0.113.10. Notes say that for each setting the first match wins, and that scp, sftp and rsync read the same file.](https://learn.benibix.com/diagrams/infc-ssh-config.svg)

### Example: Jack's six servers

Jack looks after 6 servers, each with its own address, user and port. He keeps the commands in a text file and pastes them in.

He moves them into ~/.ssh/config as 6 Host blocks. Now he types ssh db or ssh web2, and his copy jobs use the same short names.

**Words in this lesson:** [SSH Config File (~/.ssh/config)](https://learn.benibix.com/term/infrastructure/ssh-config-file)

**Question:** A setting in Host shop is ignored. What is the likely cause?

**Answer:** An earlier block in the file matched first and set it. ssh keeps the first value it finds for each setting. A block earlier in the file, such as a Host * at the top, wins over a later one.

---

Source: https://learn.benibix.com/learn/infrastructure-ssh/ssh-config-file
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
