~/.ssh/config: Host, HostName, User, Port and IdentityFile
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · OpenSSH_10.5p1updated 2026-10-20
- tool
- OpenSSH
- file
- ~/.ssh/config
- key
- Host / HostName / User / Port / IdentityFile
- type
- keyword value (one per line)
- default
- no file; built-in defaults apply
~/.ssh/config lets you type ssh prod instead of ssh -i ~/.ssh/prod_key -p 2222 deploy@203.0.113.10. Each Host block starts with one or more patterns, and the keywords below it apply when the name you type matches. For each keyword the first value found wins, so put specific hosts above Host *.
Example and the resolved result
ssh -G prints the configuration ssh would use for a host, without connecting:
cat > config <<'EOF'
Host prod
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/prod_ed25519
IdentitiesOnly yes
Host *
ServerAliveInterval 60
EOF
ssh -G -T -F config prod | grep -E '^(hostname|user|port|identityfile|identitiesonly|serveraliveinterval) 'Output
user deploy hostname 203.0.113.10 port 2222 identitiesonly yes serveraliveinterval 60 identityfile ~/.ssh/prod_ed25519
Keywords you use most
| Keyword | Meaning |
|---|---|
| Host | patterns this block applies to (alias, wildcards like *.example.com) |
| HostName | real host name or IP to connect to |
| User | remote user name |
| Port | remote port (default 22) |
| IdentityFile | private key to offer; can be repeated |
| IdentitiesOnly yes | offer only the configured keys, not every key in the agent |
| ProxyJump | connect through a bastion host |
| ServerAliveInterval | seconds between keepalives; avoids idle disconnects |
Pitfalls
- Order matters: the first matching value is used. A
UserunderHost *at the top overrides every later block. - Permissions: on Linux and macOS ssh refuses a config file that other users can write.
- Too many keys: with many keys in the agent, servers may disconnect after too many failed attempts.
IdentitiesOnly yesavoids it.
Sources
Related pages
errors · sshPermission denied (publickey) with sshssh fails with Permission denied (publickey) when the server accepts only keys and none you offer is authorized. Check the key, the user and file permissions.changes · sshOpenSSH 9.9 to 10.x: incompatible changes from 10.0 to 10.6OpenSSH 10.x: DSA removed and modp DH off by default in sshd (10.0), agent sockets moved to ~/.ssh/agent (10.1), stricter user names on the command line (10.6).flags · curlcurl -k (--insecure): skip TLS certificate verificationcurl -k, or --insecure, makes curl accept a TLS certificate it cannot verify, such as a self-signed one. Safer: --cacert for a private CA, or --pinnedpubkey.