summaryrefslogtreecommitdiff
path: root/roles/sshserver/tasks/main.yaml
blob: 6d6cc59c3b2c4b907fbea2acf5365ec54f54122c (plain) (blame)
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
---
- name: install ssh-server
  apt:
    name: openssh-server
    state: present

- name: hardening ssh-server config
  lineinfile:
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    dest: /etc/ssh/sshd_config
    mode: 0644
  with_items:
  - { regexp: "^#?\\s*IgnoreRhosts", line: "IgnoreRhosts yes" }
  - { regexp: "^#?\\s*PermitRootLogin", line: "PermitRootLogin without-password" }
  - { regexp: "^#?\\s*PubkeyAuthentication", line: "PubkeyAuthentication yes" }
  - { regexp: "^#?\\s*HostbasedAuthentication", line: "HostbasedAuthentication no"  }
  - { regexp: "^#?\\s*PermitEmptyPasswords", line: "PermitEmptyPasswords no" }
  - { regexp: "^#?\\s*UseDNS", line: "UseDNS no" }
  notify: restart ssh

- name: limit allowed users
  lineinfile:
    dest: /etc/ssh/sshd_config
    regexp: "^AllowUsers"
    line: "AllowUsers {{ ' '.join([ 'root' ] | union(sshserver_allowusers_group | default([])) | union(sshserver_allowusers_host | default([]))) }}"
  notify: restart ssh

- name: install ssh keys for root
  authorized_key:
    user: root
    key: "{{ sshserver_root_keys }}"
    exclusive: yes

- name: delete root password
  user:
    name: root
    password: "!"