SSH Config Basics
concept~/.ssh/config is a named set of connection instructions—not a routing table for hostnames. Each block gives a nickname to a full set of connection details, so ssh myserver replaces a command line full of flags.
The basic structure:
Host nickname
HostName actual-server.com
User remote-username
Port 2222
IdentityFile ~/.ssh/specific_key
IdentitiesOnly yes
The fields:
Host—what you type:ssh nicknameHostName—real address (DNS or IP)User—remote username (defaults to your local username)Port—SSH port (defaults to 22)IdentityFile—which key to useIdentitiesOnly yes—only try the specified keys
The before/after is the whole sales pitch. Without config:
ssh -i ~/.ssh/id_work_yk -p 2222 [email protected]
With config: ssh work. Short memorable names, the correct key always used, port and username remembered—and git operations against configured hosts just work.
Three consequences follow from "named instructions, not a routing table":
- Host is a label you control. It doesn't have to match the real hostname—
HostNamehandles that. This is what makes host aliases possible: two different names, two different keys, one actual server. Multi-account Git setups depend on it. - Blocks compose by pattern. Wildcards (
Host 192.168.1.*,Host *) let you set per-network keys and global defaults, with the most specific match winning. IdentitiesOnlykeeps SSH honest. Without it, SSH may try every key you own—leaking which keys you hold and tripping "too many authentication failures." With it, each block presents exactly the key you named.
When the resolved behavior surprises you, ask SSH itself: ssh -G hostname prints every option as finally resolved—which config rules matched and what values won.