iac.htora.dev · security templates

Home/Refreshers/Lock SSH down to keys only: refresher

Lock SSH down to keys only

Turn off password logins and root logins, and check the config before restarting so you cannot lock yourself out.

Remember

  1. Ansible connects: over SSH to Linux, over WinRM to Windows.
  2. Safety checks: a key exists and the new config is valid.
  3. Settings written: a drop-in on Linux, the whole file on Windows.
  4. sshd reloaded or restarted: then read back to prove passwords are off.
PlatformUsesThe part that catches people
LinuxA drop-in sshd config, validated before reloadsshd keeps the first value it reads for each setting, and it reads drop-in files in name order.
WindowsOpenSSH Server's sshd_config, tested before it goes liveThe stock sshd_config sends every member of Administrators to C:\ProgramData\ssh\administrators_authorized_keys and ignores the key in their own profile.

Run the quick start

Reach the Linux machinesansible all -i inventory.ini -m ping
Windows modules, onceansible-galaxy collection install ansible.windows:==3.3.0
Reach the Windows machinesansible all -i inventory.ini -m ansible.windows.win_ping
Previewansible-playbook -i inventory.ini playbook.yml --check --diff
Runansible-playbook -i inventory.ini playbook.yml
Run again, expect changed=0ansible-playbook -i inventory.ini playbook.yml
Check it worked

From another machine, try to log in with a password. It should be refused before it even asks.

Read the full pageDownload PDF

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.