Files
operating-automation/roles/system/tasks/ssh-hardening.yaml
2025-10-08 09:32:02 +02:00

36 lines
885 B
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- name: PublicKeys von URL holen
ansible.builtin.uri:
url: "{{ ssh_pub_key_url }}"
return_content: yes
delegate_to: localhost
register: fetched_keys
- name: Liste der einzelnen Keys erstellen
ansible.builtin.set_fact:
key_list: "{{ fetched_keys.content.splitlines() }}"
- name: authorized_keys anlegen (falls nicht vorhanden)
ansible.builtin.file:
path: "/root/.ssh/authorized_keys"
state: touch
owner: "root"
group: "root"
mode: "0600"
- name: Jeden Key einzeln mit authorized_key hinzufügen
ansible.builtin.authorized_key:
user: "root"
key: "{{ item | trim }}"
state: present
loop: "{{ key_list }}"
when: item | trim != ""
- name: Harden SSH configuration
ansible.builtin.template:
src: sshd_config.j2
dest: /etc/ssh/sshd_config
owner: root
group: root
mode: '0644'
notify:
- Restart SSH