-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh.yml
43 lines (43 loc) · 1.5 KB
/
ssh.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
- hosts: all
vars:
ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Lock down sshd with good defaults
become: true
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '{{ item.regexp }}'
line: '{{ item.line }}'
validate: /usr/sbin/sshd -t -f %s
loop:
- regexp: '(?i)^#?PermitRootLogin'
line: PermitRootLogin prohibit-password
- regexp: '(?i)^#?PermitEmptyPasswords'
line: PermitEmptyPasswords no
- regexp: (?i)^#?'Protocol'
line: Protocol 2
- regexp: '(?i)^#?PermitUserEnvironment'
line: PermitUserEnvironment no
- regexp: '(?i)^#?useprivilegeseparation'
line: >-
UsePrivilegeSeparation {{ (ansible_distribution_major_version ==
'6')|ternary('yes','sandbox') }}
- regexp: '(?i)^#?gssapiauthentication'
line: GSSAPIAuthentication no
- regexp: '(?i)^#?compression'
line: 'Compression {{ sshd_compression|default(''delayed'') }}'
- regexp: '(?i)^#?MaxAuthTries'
line: MaxAuthTries 4
- regexp: '(?i)^#?ClientAliveInterval'
line: ClientAliveInterval 30
- regexp: '(?i)^#?ClientAliveCountMax'
line: ClientAliveCountMax 20
- regexp: '(?i)^#?PasswordAuthentication'
line: PasswordAuthentication no
- regexp: '^UsePAM yes'
line: UsePAM no
- name: Restart SSH
become: true
service:
name: sshd
state: restarted