Skip to content

/config/ssh/ssh-config-file

~/.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:

bash
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

KeywordMeaning
Hostpatterns this block applies to (alias, wildcards like *.example.com)
HostNamereal host name or IP to connect to
Userremote user name
Portremote port (default 22)
IdentityFileprivate key to offer; can be repeated
IdentitiesOnly yesoffer only the configured keys, not every key in the agent
ProxyJumpconnect through a bastion host
ServerAliveIntervalseconds between keepalives; avoids idle disconnects

Pitfalls

  • Order matters: the first matching value is used. A User under Host * 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 yes avoids it.

Sources