ls-2024-selection/ansible/playbooks/04-update-sshd-config.yml

43 lines
1.0 KiB
YAML
Raw Normal View History

2024-02-02 12:18:11 +01:00
---
- name: Update SSH server configuration
hosts: your_target_host
become: yes
tasks:
- name: Disable empty password login
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PermitEmptyPasswords'
line: 'PermitEmptyPasswords no'
notify:
- Restart SSH
- name: Disable password authentication
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PasswordAuthentication'
line: 'PasswordAuthentication no'
notify:
- Restart SSH
- name: Update AuthorizedKeysFile
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^AuthorizedKeysFile'
line: 'AuthorizedKeysFile .ssh/authorized_keys'
notify:
- Restart SSH
- name: Remove other AuthorizedKeysFile settings
replace:
path: /etc/ssh/sshd_config
regexp: '^AuthorizedKeysFile.*'
replace: ''
notify:
- Restart SSH
handlers:
- name: Restart SSH
service:
name: sshd
state: restarted