How to set up your SSH config file (~/.ssh/config)
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with OpenSSH 9.6p1, client and server, November 29, 2026.
The SSH config file, ~/.ssh/config, saves the details for each server so you can type ssh web instead of ssh -i ~/.ssh/id_ed25519 -p 2222 ubuntu@203.0.113.10. Create it, add a Host block per server and set its permissions:
Host web
HostName 203.0.113.10
User ubuntu
Port 2222
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
chmod 600 ~/.ssh/config
ssh web
We tested these examples with OpenSSH 9.6 against a local server: a Host web block like the one above connected with just ssh web, and scp reached the same server through that block (scp f.txt web:/tmp/). sftp and Git read the same file.
How SSH matches blocks: first value wins
For each option, SSH uses the first value it finds, reading the file from the top. Two things follow:
- Put specific hosts first and
Host *last. In our test, a file withHost *settingUser nobodyaboveHost websettingUser rootresolved to usernobody. With the order swapped, it resolved toroot. - A second block for the same host can’t override the first. We added a later
Host webblock withPort 9999; SSH kept port 2222 from the first block.
To see the final settings for a host, ask SSH:
ssh -G web | grep -E '^(hostname|user|port|identityfile) '
ssh -G prints every option after matching, without connecting. It’s the fastest way to debug a config that isn’t doing what you expect.
Useful examples
Defaults for every server (at the bottom of the file):
Host *
ServerAliveInterval 60
AddKeysToAgent yes
ServerAliveInterval keeps idle sessions from being dropped. On a Mac, UseKeychain yes also stores key passphrases in the keychain (Apple’s OpenSSH only; we didn’t test it).
A server you reach through another one (bastion or jump host):
Host internal-db
HostName 10.0.1.20
User admin
ProxyJump bastion.example.com
Several servers with one pattern:
Host *.dev.example.com
User deploy
IdentityFile ~/.ssh/deploy_key
GitHub with a second account:
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work_ed25519
IdentitiesOnly yes
Then clone with git clone git@github-work:company/repo.git.
Split a long file: Include ~/.ssh/config.d/* at the top of ~/.ssh/config reads every file in that folder. In our test a host defined only in an included file resolved correctly.
Errors from the config file
| Message | Cause | Fix |
|---|---|---|
Bad owner or permissions on /home/you/.ssh/config |
Other users can write to the file | chmod 600 ~/.ssh/config |
Bad configuration option: hostnme |
A misspelled option name | Fix the spelling; SSH names the line |
Could not resolve hostname web |
No Host web block, or a typo in the name |
Check the block and ssh -G web |
| An option seems ignored | An earlier block already set it | Move specific Host blocks above Host * |
We triggered the first two in our test: a config file with 666 permissions gave Bad owner or permissions, and a misspelled Hostnme line gave line 2: Bad configuration option: hostnme followed by terminating, 1 bad configuration options.
For the full option list, see the ssh_config manual page. Related: Too many authentication failures (fixed with IdentitiesOnly yes), Could not resolve hostname and the known_hosts file.
FAQ
Where is the SSH config file?
~/.ssh/config for your user on macOS and Linux, and C:\Users\you\.ssh\config on Windows. It doesn't exist until you create it. The system-wide file is /etc/ssh/ssh_config, which your own file overrides.
Why isn't my config being used?
Check three things: the file is exactly ~/.ssh/config with no extension, its permissions aren't open to other users (chmod 600), and no earlier Host block already set the same option. ssh -G host shows what SSH actually uses.
Is the server's sshd_config the same thing?
No. ~/.ssh/config and /etc/ssh/ssh_config configure the client you connect from. /etc/ssh/sshd_config configures the SSH server and lives on the machine you connect to.
