-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-add-ssh-user.yaml
53 lines (46 loc) · 1.13 KB
/
01-add-ssh-user.yaml
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
44
45
46
47
48
49
50
51
52
53
---
- hosts: host
vars_files:
- variables/ssh.yaml
tasks:
- name: Add a new user
user:
name={{ ssh_user }}
password={{ ssh_password }}
shell=/usr/bin/bash
- name: Grant login access from local machine
authorized_key: user={{ ssh_user }}
key="{{ lookup('file', public_key_path) }}"
state=present
- name: Disable password authentication
lineinfile:
dest=/etc/ssh/sshd_config
regexp='^PasswordAuthentication'
line="PasswordAuthentication no"
state=present
backup=yes
notify:
- restart ssh
- name: Disable root login
lineinfile:
dest=/etc/ssh/sshd_config
regexp="^PermitRootLogin"
line="PermitRootLogin no"
state=present
backup=yes
notify:
- restart ssh
- name: Change ssh port
lineinfile:
dest=/etc/ssh/sshd_config
regexp="^Port"
line="Port {{ ssh_port }}"
state=present
backup=yes
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name=sshd
state=restarted