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
- Ansible connects: over SSH to Linux, over WinRM to Windows.
- Safety checks: a key exists and the new config is valid.
- Settings written: a drop-in on Linux, the whole file on Windows.
- sshd reloaded or restarted: then read back to prove passwords are off.
| Platform | Uses | The part that catches people |
|---|---|---|
| Linux | A drop-in sshd config, validated before reload | sshd keeps the first value it reads for each setting, and it reads drop-in files in name order. |
| Windows | OpenSSH Server's sshd_config, tested before it goes live | The 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 machines | ansible all -i inventory.ini -m ping |
| Windows modules, once | ansible-galaxy collection install ansible.windows:==3.3.0 |
| Reach the Windows machines | ansible all -i inventory.ini -m ansible.windows.win_ping |
| Preview | ansible-playbook -i inventory.ini playbook.yml --check --diff |
| Run | ansible-playbook -i inventory.ini playbook.yml |
| Run again, expect changed=0 | ansible-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.