SSH Configuration and Access Recovery
Quick answer
Client configuration chooses how to connect. Server configuration controls accepted connections and authentication policy. Validate proposed changes and keep alternate access before applying them.
Prepare the practice environment
Run python3 lab-fixtures/ssh-transfer/setup.py from the extracted package root as an ordinary user. Enter the printed private path and check pwd. Use a fresh fixture and Bash with LC_ALL=C and pipefail. Only local rsync and synthetic files are tested here. For manual SSH examples use an isolated authorized VM network, snapshot, console access, provisioned learner account and independently verified host keys; see the lab guide. Never use real credentials or external hosts.
How it works
Client Host blocks select options such as User, HostName, IdentityFile and StrictHostKeyChecking. ssh -G prints evaluated client configuration without connecting. sshd -t checks server configuration and host keys; sshd -T prints effective configuration, with -C for connection-specific Match evaluation. Include files, ordering and Match rules matter. For password-to-key migration first test a separate key-based session while keeping console access and the old session; only then consider a reviewed policy change and test another new session. Syntax success does not prove access succeeds.
For many single-valued OpenSSH client options, the first applicable value wins. Place specific Host entries before general defaults; some options, such as IdentityFile, can accumulate values instead. Inspect the evaluated configuration for the intended host alias rather than trusting indentation or the last line. Keep offline checks distinct from a successful new VM login.
Try the examples
grep -E '^(PermitRootLogin|PubkeyAuthentication) ' sshd_config.sampleText inspection only; not a parser and not evidence of effective policy.
Expected stdout:
PermitRootLogin noPubkeyAuthentication yesssh -G -F ./ssh_config.sample lab-server.example | grep -E "^(hostname|user|stricthostkeychecking) "VM only; no connection is made. Output order and spelling vary with version.
Manual example; not executed locally. Follow its stated environment restrictions.
Authorized disposable VM with installed server and lab host keys; do not copy this partial policy sample into /etc. A successful command is normally silent.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not close the existing session or disable password authentication until alternate access is proven. Do not solve Permission denied by relaxing key-file permissions or bypassing verification.
Practice
Write a rollback checklist: console, backup, syntax validation, effective policy review, new-session test and restoration of the previous policy if necessary.
Related references
Study: sshd, ssh. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SSH configuration and access recovery — Knowledge Check
Apply SSH trust and transfer concepts to synthetic fixtures and VM-only scenarios.
What does ssh -G do?
What does a successful sshd -t prove?
Before changing remote authentication policy?
Which construct can change policy for specific connections?