A short, practical introduction to Host blocks, OpenSSH matching, and safer defaults. Read the three lessons, solve the exercise, then check the result in the browser.
15 minutesBeginner3 lessons and 1 exercise
Three ideas that prevent most config mistakes
01
Give connections useful names
A Host block creates an alias. HostName is the real server, while User and IdentityFile provide connection-specific settings. You can then run ssh school-server instead of remembering every option.
Host school-server
HostName 203.0.113.42
User student
IdentityFile ~/.ssh/id_ed25519
Remember: Host is the name you type. HostName is the server SSH connects to.
02
Specific hosts belong before Host *
For many options, OpenSSH keeps the first value it obtains. A broad Host * block near the top can therefore win before a later specific block is evaluated.
Host school-server
User student
Host *
User deploy
Remember: Put specific Host blocks first and shared defaults at the end.
03
Prefer safe, narrow settings
Do not disable host key checks globally. Keep forwarding off by default and enable it only for a trusted host that actually needs it. OpenSSH defaults are usually a better starting point than copied legacy settings.
Host legacy-lab
StrictHostKeyChecking accept-new
ForwardAgent no
Remember: Scope exceptions to one host instead of weakening every connection.
CLASSROOM EXERCISE
Find three problems in this config
Answer each question. The related config line is highlighted while you work, and the corrected version unlocks after all three answers are right.
Configuration to inspect
Host * StrictHostKeyChecking no User deployHost school-server HostName 203.0.113.42 User studentHost school-server IdentityFile ~/.ssh/id_ed25519
Solved 0 of 3
Using this in a lesson
Using this in a lesson
The exercise works as a short individual task or a pair discussion. No account, installation, or uploaded file is required.
Give learners 5 minutes to explain each problem.
Compare answers in pairs and propose a corrected config.
Paste the correction into the checker and discuss every remaining finding.