SSH config file shortcuts
The SSH config file stores per-host settings such as user, port and key, so a short alias replaces a long ssh command.
- Updated Nov 27, 2026
- Markdown
Give a server a short alias in ~/.ssh/config so ssh myserver replaces a long command.
- A server you already log in to with an SSH key
With the SSH config file, a short entry in ~/.ssh/config turns a long command into ssh myserver. Once you manage two or three servers, commands like ssh -p 2222 -i ~/.ssh/work_ed25519 deploy@203.0.113.10 get tiresome and easy to mistype. The same details also have to match in scp and rsync. A short entry in your SSH config file turns all of that into ssh myserver.
How it works#
When you run ssh <name>, the client reads the SSH config file ~/.ssh/config on your own computer, then the system file /etc/ssh/ssh_config. It collects every Host block whose pattern matches the name you typed. For each option, the first value found wins. This is why specific entries go at the top and the catch-all Host * goes last.
The alias is only a label on your side. HostName holds the real address that is used for the connection. Everything you put in the entry (user, port, key) is used as if you had passed it on the command line, and a flag you type directly still overrides the file.
Because scp, rsync -e ssh and git over SSH all run ssh underneath, they use the same file. One entry works for all of them.
Useful options:
| Option | Meaning |
|---|---|
HostName | The real IP address or domain |
User | Login name |
Port | SSH port, if not 22 |
IdentityFile | Private key to use |
IdentitiesOnly yes | Offer only the named key, not every key in the agent |
ProxyJump | Reach the host through another SSH host |
ServerAliveInterval | Send a keepalive every N seconds |
Step 1: Create or open the file#
On your own computer, not the server:
mkdir -p ~/.ssh
nano ~/.ssh/configWhat you should see: an empty editor if the file is new, or your existing entries.
Step 2: Add a host entry#
Host myserver
HostName 203.0.113.10
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yesWhat each line does:
Host: the alias you type.HostName: the real IP address or domain.User: the login name.Port: the SSH port, only needed if it is not 22.IdentityFile: the private key to use.IdentitiesOnly: use only that key, which avoids trying many keys from your agent.
The indented lines belong to the Host above them. Indentation is for readability, but a blank line or new Host ends the block.
Step 3: Set permissions#
SSH refuses a config file that others can write to (see file permissions):
chmod 600 ~/.ssh/configWhat you should see: no output.
Step 4: Add shared defaults (optional)#
Settings under Host * apply to every host. Put it last, because the first value found for each option wins:
Host *
ServerAliveInterval 60
AddKeysToAgent yesServerAliveInterval helps keep idle sessions from being dropped. AddKeysToAgent yes adds a key to your agent the first time you unlock it.
Step 5: Reach a private server through a jump host (optional)#
If a server has no public address, connect through one that does:
Host private-db
HostName 10.0.0.5
User deploy
ProxyJump myserverNow ssh private-db logs in to myserver first and then opens the real connection from there. Your private key stays on your own computer.
Check it worked#
ssh myserverYou should land in a shell on the server with no need to type the user, IP or key. To see exactly what SSH will use, run:
ssh -G myserver | grep -E '^(hostname|user|port|identityfile) 'The output should show the values from your entry, each in lower case on its own line.
Edge cases and gotchas#
- Order matters, first value wins. If a general block above your entry sets
User, it beats the user in the entry below. Keep specific hosts first andHost *last. - Patterns match the alias, not the real name.
Host web-*matches what you typed afterssh, not theHostName. A pattern like*.example.commatches only if you typed that full name. - Too many keys cause failures before yours is tried. An agent holding many keys can hit the server’s attempt limit.
IdentitiesOnly yesfixes it. - Windows and WSL use different home folders. The file lives under the user profile of whichever environment runs
ssh. An entry in WSL is invisible to the Windows client, and the reverse. - IPv6
HostNamevalues need no brackets. WriteHostName 2001:db8::10here. Brackets are only forscpandrsynctargets on the command line. - A changed host key still warns. The config does not hide host key changes. See What is SSH for what to do.
- Do not store secrets in the file. It holds paths and names, which is fine. Never paste a private key or a password into it.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Bad owner or permissions on /home/you/.ssh/config | File is writable by others, or owned by another user | Run chmod 600 ~/.ssh/config and check the owner |
Could not resolve hostname myserver | Typo in Host, or you are editing on the wrong machine | Check the spelling and that the file is on the computer you connect from |
Permission denied (publickey) | Wrong IdentityFile, or the public key is not on the server | Fix the path, see Log in with SSH keys |
Too many authentication failures | The agent offers many keys before the right one | Add IdentitiesOnly yes |
| Settings seem ignored | An earlier block already set that option | Run ssh -G myserver to see the effective value and reorder |
/home/you/.ssh/config: line 4: Bad configuration option | Typo in an option name | Fix the named line |
ssh: connect to host ... port 22: Connection refused using the alias | HostName or Port in the entry is wrong | Run ssh -G myserver and check both |
| The alias works in the terminal but not in a GUI tool | The tool does not read ~/.ssh/config | Use the full host, user and key in the tool |
Real-world scenario#
You manage a web server, a database host that has no public address, and a staging box. Typing the full command each time led to mistakes, once with the wrong key.
You write three entries in ~/.ssh/config: web, staging, and db with ProxyJump web. A Host * block at the bottom sets ServerAliveInterval 60. You run chmod 600 ~/.ssh/config.
Now ssh web, ssh db and scp backup.sql db:/tmp/ all work. When something breaks you run ssh -G db and read the user, port and key it will use, which finds the typo in seconds.
Quick reference#
| Option | Example |
|---|---|
Host | Host myserver |
HostName | HostName 203.0.113.10 |
User | User deploy |
Port | Port 2222 |
IdentityFile | IdentityFile ~/.ssh/id_ed25519 |
IdentitiesOnly | IdentitiesOnly yes |
ProxyJump | ProxyJump web |
| Check | ssh -G myserver |
Related lessons#
- Log in with SSH keys: create the key the entry points to
- Copy files with scp and rsync: both use your aliases
- Linux file permissions explained: why the config needs mode 600
Next#
You have finished the Server basics track. Continue with Install Docker on Ubuntu.
Check what you learned
Frequently asked questions
Does the config file work with scp and rsync?
Yes. They use SSH underneath, so scp file.txt myserver:/tmp/ and rsync -av ./dir/ myserver:/tmp/dir/ both use your aliases.
Can I use one alias for several servers?
Use a pattern such as Host web-* for shared settings, and define each server with its own Host block for the HostName.
Why do I get Too many authentication failures?
Your SSH agent offers every key it holds and the server gives up after a few. Add IdentitiesOnly yes to the host entry so SSH offers only the key named by IdentityFile.
Do I put this file on the server?
No. It is the client config, read on the computer you connect from. The server's settings live in /etc/ssh/sshd_config, which is a different file.
Sources
Keep going: guides and tutorials
- Install a Self-Hosted PaaS on Your Own Server in Five Minutes One installer download, one setup token, one sample app. The full Levelrail install on a fresh Linux server, with the checks and the fixes.
- Manage Secrets Self-Hosted: Env Vars and Master Key Rotation Set env vars and encrypted secrets on a self-hosted server, apply changes safely, and rotate the master key with no downtime without locking yourself out.