~/.ssh/config — OpenSSH client configuration
Client config applies per destination. Command-line options normally precede user config, then system config; most scalar options use first applicable value, so specific Host sections precede Host *. IdentityFile is additive. HostName sets destination, User selects remote identity, IdentityFile specifies a credential path, and IdentitiesOnly restricts offered identities. Default user usually matches local login; default port 22; package and system config can differ. Preserve host-key checking and never put private key contents in config. User configuration must not be writable by others; protect private keys separately. ssh -G with a trusted standalone file prints evaluated options without connecting, but arbitrary config can contain Match exec, so never evaluate untrusted files. Changes apply to new connections, not existing multiplexed sessions. Restore prior config and re-evaluate before reconnecting.
Formal Syntax & Structure
Host ALIAS HostName NAME User ACCOUNT IdentityFile PATH IdentitiesOnly yesParameters & Attributes
| Name | Type | Description |
|---|---|---|
| Host | directive | Alias or host pattern |
| HostName | directive | Actual destination |
| User | directive | Remote account |
| IdentityFile | directive | Credential path; may repeat |
| IdentitiesOnly | directive | Restrict offered identities |
Return Value
Evaluated client settings; no connection or authentication performed by this example.
Working Example
set -eud=$(mktemp -d)trap 'rm -rf -- "$d"' EXITcat > "$d/config" <<'EOF'Host bm-lab HostName lab.example User studentHost * User fallbackEOFssh -G -F "$d/config" bm-lab 2> "$d/ssh.stderr" | awk '$1=="user" || $1=="hostname" {print}'