configuration

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

linux syntaxlinux
Host ALIAS    HostName NAME    User ACCOUNT    IdentityFile PATH    IdentitiesOnly yes

Parameters & Attributes

NameTypeDescription
HostdirectiveAlias or host pattern
HostNamedirectiveActual destination
UserdirectiveRemote account
IdentityFiledirectiveCredential path; may repeat
IdentitiesOnlydirectiveRestrict offered identities

Return Value

configuration or inspection

Evaluated client settings; no connection or authentication performed by this example.

Working Example

Example Snippetlinux
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}'
Linux Reference