Skip to content
Snippets Groups Projects
Commit 50f07f80 authored by Baptiste DE RENZO's avatar Baptiste DE RENZO
Browse files

Merge branch 't37430-verify-key-before-permitrootlogin-modification' into 'main'

Verify root ssh authorized key file before permitrootlogin modification, Refs #37430

See merge request sys/ansible-public!38
parents 552f577d 960b6b87
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,18 @@ ...@@ -96,7 +96,18 @@
backup: true backup: true
notify: restart unattended-upgrades notify: restart unattended-upgrades
- name: enable root login via ssh with key - name: verify root user ssh authorized key file
ansible.builtin.stat:
path: /root/.ssh/authorized_keys
register: auth
- name: fail if the root ssh authorized key is missing or empty
ansible.builtin.fail:
msg: "Error: root user does not have any ssh key configured !\n\
Cannot configure PermitRootLogin to without-password"
when: not auth.stat.exists or auth.stat.size == 0
- name: enable root login via ssh with key only
ansible.builtin.replace: ansible.builtin.replace:
dest: /etc/ssh/sshd_config dest: /etc/ssh/sshd_config
regexp: ^#?PermitRootLogin.* regexp: ^#?PermitRootLogin.*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment