SSH config is the OpenSSH client configuration file, usually ~/.ssh/config, that saves per-host connection settings such as hostname, username, port, identity file and jump host. Once a host is defined there, you connect with a short alias like ssh myserver instead of typing the full command, and the same settings apply to scp, sftp and rsync over SSH.
Key takeaways
- The SSH config file lives at ~/.ssh/config and turns long SSH commands into short, repeatable aliases.
- Put specific Host blocks first and Host * defaults last, because the first matching value for each option wins.
- Keep the file at chmod 600 and use keys, IdentitiesOnly and ProxyJump instead of passwords wherever possible.
If you connect to servers by SSH, you have typed the same long command too many times: a username, an IP address, a non-standard port and a key file. The SSH config file saves all of that once, so every later connection is one short word.
What is SSH config?
SSH config is the configuration file for the OpenSSH client, normally ~/.ssh/config, that stores per-host connection settings such as the real hostname, username, port, key file and jump host.
Every time you run ssh, scp, sftp or rsync over SSH, the client reads this file and applies the matching settings. You define a host once, then connect with its alias. The OpenBSD ssh_config manual page describes the file as containing sections separated by Host specifications, each applied only to hosts matching that pattern.
There are two client files. Your personal file is ~/.ssh/config and applies only to you. The system-wide file is /etc/ssh/ssh_config and applies to every user. Your personal file is read first, so it wins when both set the same option.
Where is the SSH config file and how do I create it?
On Linux and macOS the file is ~/.ssh/config. On Windows, the built-in OpenSSH client uses %USERPROFILE%\.ssh\config, for example C:\Users\You\.ssh\config.
The file does not exist by default, so create it yourself and lock down its permissions. SSH ignores a config file that is too open, because it may contain key paths and host details.
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
That is 600 on the file, meaning only you can read and write it, and 700 on the .ssh directory. If SSH still ignores the file, permissions are the first thing to check. Our guide to securing your Wi-Fi covers the same habit of locking down the basics before adding clever features.
How does the SSH config file work?
The file is plain text made of Host blocks. A Host line opens a block, and every indented line after it belongs to that block until the next Host line.
Host staging
HostName 203.0.113.50
User ubuntu
Port 2222
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Now ssh staging expands to the full connection: user ubuntu, host 203.0.113.50, port 2222, with the work key. Host is the alias you type; HostName is the real address.
Indentation is cosmetic and makes blocks readable, but SSH ignores it. Keywords are case-insensitive, while values usually are not. You can separate a keyword and its value with a space or with =.
Why does the order of Host blocks matter?
Order matters because SSH applies the first value it finds for each option. It reads from the top, and once an option has a value, later blocks cannot change it.
Put specific host blocks first and general wildcard blocks last. A Host * block at the top would set defaults for everything and block your specific settings below it. This is the most common SSH config mistake.
Host db-prod
HostName db.example.com
User postgres
Host *.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519
Host *
ServerAliveInterval 60
IdentitiesOnly yes
In this example, ssh db-prod uses user postgres, because that specific block comes first. Any other *.example.com host uses deploy. Every host gets the keep-alive and IdentitiesOnly defaults from Host *.
What are the most useful SSH config options?
Most people need only a dozen options. The table below covers the ones you will actually use, with what each one does.
| Option | What it does | Example |
|---|---|---|
| Host | Alias and pattern for the block | Host staging |
| HostName | Real hostname or IP address | HostName 203.0.113.50 |
| User | Remote username | User ubuntu |
| Port | Remote port, default 22 | Port 2222 |
| IdentityFile | Private key to use | IdentityFile ~/.ssh/id_ed25519 |
| IdentitiesOnly | Offer only the listed keys | IdentitiesOnly yes |
| ProxyJump | Connect through a jump host | ProxyJump bastion |
| ForwardAgent | Forward your local agent | ForwardAgent yes |
| ServerAliveInterval | Seconds between keep-alives | ServerAliveInterval 60 |
| StrictHostKeyChecking | How to handle unknown host keys | StrictHostKeyChecking ask |
| LocalForward | Forward a local port | LocalForward 8080 localhost:80 |
| Include | Load another config file | Include ~/.ssh/config.d/* |
Two options deserve extra care. StrictHostKeyChecking should stay at ask or yes on real systems; setting it to no silently accepts any host key and defeats protection against impersonation. ForwardAgent is convenient but forwards your agent to the remote host, so only enable it for hosts you trust.
How do wildcards and Match blocks work?
Host patterns support glob wildcards. * matches anything, ? matches one character, and ! at the start negates a pattern.
Host *.internal.example.com !db.internal.example.com
ProxyJump bastion
User ops
This block applies to every internal host except the database host. Negated patterns are checked first, so the exception works even though the wildcard would otherwise match.
Match blocks go further and match on the user, the local host, the original host or the command being run. They are useful for rules such as only forwarding an agent when you are the deploy user, but most personal configs never need them. Keep wildcards simple and explicit.
How do I use SSH config with jump hosts?
A jump host, or bastion, is a server you connect through to reach servers that are not directly reachable. ProxyJump is the modern way to set this up.
Host bastion
HostName bastion.example.com
User ops
Host web-internal
HostName 10.0.4.12
User deploy
ProxyJump bastion
Now ssh web-internal connects to the bastion first, then on to the private address. You never type the two-step command, and scp and sftp follow the same path automatically.
For several hops, list them separated by commas: ProxyJump bastion,dmz-jump. DigitalOcean's SSH client configuration guide covers the same structure in detail. For older servers or unusual proxies, ProxyCommand gives full control, but try ProxyJump first.
How do I manage multiple keys and GitHub accounts?
Multiple keys are the most common reason people learn SSH config. Each host gets its own IdentityFile, and IdentitiesOnly yes stops SSH offering the wrong keys first.
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Clone personal projects with [email protected]:you/repo.git and work projects with git@github-work:org/repo.git. The alias changes which key is offered, even though both connect to the same real hostname.
Without IdentitiesOnly, SSH tries every key loaded in your agent. Some servers limit authentication attempts, so a long key list can lock you out with "too many authentication failures" before the right key is tried.
How do I make my SSH config more secure?
Your config file is a security control, not just a convenience. A few settings reduce real risk.
- Use keys, not passwords. Generate Ed25519 keys with a passphrase and store them in
ssh-agent. Disable password authentication on servers you control. - Set IdentitiesOnly yes in Host *. This stops SSH leaking the fact that you hold other keys to every server you touch.
- Keep StrictHostKeyChecking on. Never set it to
noin a shared or permanent config. If a host key changes, stop and investigate instead of bypassing the warning. - Limit agent forwarding. Enable
ForwardAgentonly for specific trusted hosts, never inHost *. - Use ProxyJump, not open ports. Keep internal servers off the public internet and reach them through a bastion.
- Split configs with Include. Put work hosts in
~/.ssh/config.d/workand personal hosts elsewhere, so you can share or back up one without the other.
On the server side, the matching file is sshd_config. That is where you disable root login and password authentication. Do not confuse the two files: one configures your client, the other configures who can connect to a server.
How do I debug an SSH config that is not working?
Start with ssh -G, which prints the effective configuration for a host after all blocks are merged. If the output does not show your setting, the block is not matching or an earlier block already set the value.
ssh -G staging
ssh -v staging
The -v flag adds verbose output and shows which config files were read and which key was offered. See our guide to securing your Wi-Fi for the same check-the-basics habit on home networks. Add more v letters, up to -vvv, for deeper detail.
Common fixes, in order: check chmod 600 on the file, check the alias spelling against the Host line, move specific blocks above Host *, and confirm the key file path exists. If you suspect a stale host key, check whether the server was rebuilt before deleting anything from ~/.ssh/known_hosts.
The bottom line
SSH config is a small file with an outsized payoff. Define each host once, with the right user, port, key and jump host, and every later connection becomes a short alias that works the same way in ssh, scp and sftp.
Start with one host, set the permissions to 600, put specific blocks above Host *, and add keys and jump hosts as you go. You can check the network side of a connection with our free IP checker when a host seems unreachable.
Frequently asked questions
Where is the SSH config file?
On Linux and macOS it is ~/.ssh/config, and on Windows it is %USERPROFILE%\.ssh\config. The file does not exist by default; you create it. The system-wide client file is /etc/ssh/ssh_config, which applies to every user on the machine.
What is the difference between ssh_config and sshd_config?
ssh_config configures the SSH client, the program you run to connect out. sshd_config configures the SSH server daemon, which controls who can connect in. Editing the wrong one is a common mistake, so check the filename before you save.
Why is my SSH config being ignored?
The usual causes are wrong permissions, a Host block in the wrong order, or a typo in the alias. Set chmod 600 on the file and chmod 700 on ~/.ssh, put specific blocks above Host *, and test with ssh -G hostname to see the settings SSH will actually use.
What does Host * mean in SSH config?
Host * is a wildcard block that matches every host, so it is the place for defaults such as ServerAliveInterval or IdentitiesOnly. Because the first matching value wins, Host * must come last, after all specific host blocks.
How do I use a different SSH key for one host?
Add IdentityFile ~/.ssh/id_ed25519_work inside that host's block, and add IdentitiesOnly yes so SSH offers only that key. Without IdentitiesOnly, SSH may try every key in your agent first, which can trigger too-many-authentication-failures on some servers.
Can SSH config handle jump hosts?
Yes. Add ProxyJump user@jumphost to the target host's block, or use ProxyCommand for older setups. ProxyJump is simpler and works with scp and sftp too, because they read the same config file.
Is it safe to store passwords in SSH config?
No. SSH config has no option for storing a password, and that is by design. Use SSH keys with a passphrase, ideally held in ssh-agent, and disable password authentication on servers you control.
How do I check which settings SSH will use?
Run ssh -G hostname, replacing hostname with the alias or address you type. It prints the effective configuration after all matching blocks are merged, which is the fastest way to debug a config that is not behaving as expected.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against the OpenBSD ssh_config(5) manual page and DigitalOcean's SSH client configuration guide.
How we write and fact-check →