users/tasks/sshd.yml
2024-12-17 17:48:17 +01:00

34 lines
1006 B
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
- name: user | disable SSH access for root
replace:
dest: /etc/ssh/sshd_config
regexp: '^PermitRootLogin (yes|without-password|prohibit-password)'
replace: "PermitRootLogin no"
validate: '/usr/sbin/sshd -T -f %s'
notify: reload shd
#- name: user | verify AllowUsers directive
# command: "grep -E '^AllowUsers' /etc/ssh/sshd_config"
# changed_when: False
# failed_when: False
# register: grep_allowusers_ssh
#
#- name: "add AllowUsers sshd directive"
# lineinfile:
# dest: /etc/ssh/sshd_config
# line: "\nAllowUsers "
# insertafter: 'Subsystem'
# validate: '/usr/sbin/sshd -T -f %s'
# register: allowusers_added
# when: grep_allowusers_ssh.rc != 0
#- name: "append username to AllowUsers sshd directive"
# replace:
# dest: /etc/ssh/sshd_config
# regexp: '^(AllowUsers(?!.*\b{{ item.key }}\b).*)$'
# replace: '\1 {{ item.key }}'
# validate: '/usr/sbin/sshd -T -f %s'
# with_dict: "{{ user.name }}"
# when: allowusers_added
# notify: "reload SSH"