mirror of
https://github.com/fscotto/infra.git
synced 2026-05-30 15:39:58 +00:00
Harden SSH access on server profile
This commit is contained in:
@@ -30,3 +30,9 @@ server_templates:
|
||||
server_ufw_rules:
|
||||
- rule: allow
|
||||
name: OpenSSH
|
||||
|
||||
server_sshd_settings:
|
||||
PermitRootLogin: "no"
|
||||
|
||||
server_sshd_allow_users:
|
||||
- "{{ username }}"
|
||||
|
||||
6
ansible/roles/profile_server/handlers/main.yml
Normal file
6
ansible/roles/profile_server/handlers/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Reload SSH service
|
||||
tags: [services]
|
||||
ansible.builtin.service:
|
||||
name: ssh
|
||||
state: reloaded
|
||||
@@ -24,6 +24,27 @@
|
||||
loop_control:
|
||||
label: "{{ item.dest }}"
|
||||
|
||||
- name: Disable SSH root login on server
|
||||
tags: [services]
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: '^\s*PermitRootLogin\s+'
|
||||
line: "PermitRootLogin {{ server_sshd_settings.PermitRootLogin }}"
|
||||
state: present
|
||||
validate: "sshd -t -f %s"
|
||||
notify: Reload SSH service
|
||||
|
||||
- name: Restrict SSH login to allowed users on server
|
||||
tags: [services]
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: '^\s*AllowUsers\s+'
|
||||
line: "AllowUsers {{ server_sshd_allow_users | join(' ') }}"
|
||||
state: present
|
||||
validate: "sshd -t -f %s"
|
||||
notify: Reload SSH service
|
||||
when: (server_sshd_allow_users | default([])) | length > 0
|
||||
|
||||
- name: Apply server UFW rules
|
||||
tags: [services, packages]
|
||||
community.general.ufw:
|
||||
|
||||
Reference in New Issue
Block a user