Skip to content

Commit f958ee6

Browse files
authored
Merge pull request #85 from richlamdev/fix-ssh-config
fix ssh configuration deployment
2 parents a772445 + f013ecb commit f958ee6

File tree

4 files changed

+116
-29
lines changed

4 files changed

+116
-29
lines changed

main.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
- vars.yml
1010

1111
roles:
12-
# - auto-update
13-
# - base
14-
# - aws
15-
# - brave
16-
# - chrome
17-
# # - docker-cli-only
18-
# - docker-desktop-dependency
19-
# - gh_cli
20-
# - hashicorp
21-
# - keepassxc
22-
# - kubectl
23-
# - microsoft
12+
- auto-update
13+
- base
14+
- aws
15+
- brave
16+
- chrome
17+
# - docker-cli-only
18+
- docker-desktop-dependency
19+
- gh_cli
20+
- hashicorp
21+
- keepassxc
22+
- kubectl
23+
- microsoft
2424
- mullvad
25-
# - opera
26-
# - signal-desktop
27-
# - sublime-text
28-
# - trivy
25+
- opera
26+
- signal-desktop
27+
- sublime-text
28+
- trivy
2929
- role: vim
3030
become: false
3131
- role: env
3232
become: false
33-
# - disable-local-dns
33+
- disable-local-dns
3434
# - yubico

roles/base/files/ssh_config.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
2+
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,ssh-rsa
3+
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
4+
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
5+
PubkeyAuthentication yes
6+
TCPKeepAlive yes
7+
ServerAliveInterval 600
8+
ServerAliveCountMax 5

roles/base/files/sshd_config.conf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Port 22
2+
Protocol 2
3+
PermitRootLogin no
4+
PermitUserEnvironment yes
5+
UseDNS no
6+
7+
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
8+
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,ssh-rsa
9+
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
10+
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
11+
12+
AllowTcpForwarding no
13+
AllowStreamLocalForwarding no
14+
GatewayPorts no
15+
PermitTunnel no
16+
AddressFamily inet
17+
18+
HostBasedAuthentication no
19+
IgnoreUserKnownHosts yes
20+
GSSAPIAuthentication no
21+
KerberosAuthentication no
22+
23+
HostKey /etc/ssh/ssh_host_ed25519_key
24+
25+
TCPKeepAlive yes
26+
ClientAliveInterval 600
27+
ClientAliveCountMax 5
28+
29+
X11Forwarding no
30+
31+
# Logging
32+
SyslogFacility AUTHPRIV
33+
LogLevel VERBOSE
34+
35+
PubkeyAuthentication yes
36+
37+
# Change below to "yes" to enable password auth
38+
ChallengeResponseAuthentication no
39+
PasswordAuthentication no

roles/base/tasks/authentication.yml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
11
---
2-
# SSH server and client config changes
3-
- name: authentication | sshd_config
4-
template:
5-
src: "sshd_config.j2"
6-
dest: "/etc/ssh/sshd_config"
7-
mode: 0644
2+
- name: Find all files in /etc/ssh/sshd_config.d/
3+
ansible.builtin.find:
4+
paths: /etc/ssh/sshd_config.d/
5+
file_type: file
6+
register: sshd_config_files
7+
8+
- name: Remove all files in /etc/ssh/sshd_config.d/
9+
ansible.builtin.file:
10+
path: "{{ item.path }}"
11+
state: absent
12+
loop: "{{ sshd_config_files.files }}"
13+
when: sshd_config_files.matched > 0
14+
15+
- name: Ensure /etc/ssh/sshd_config.d/ directory exists
16+
ansible.builtin.file:
17+
path: /etc/ssh/sshd_config.d/
18+
state: directory
19+
owner: root
20+
group: root
21+
mode: '0755'
22+
23+
- name: Copy custom sshd_config.conf to /etc/ssh/sshd_config.d/
24+
ansible.builtin.copy:
25+
src: "sshd_config.conf"
26+
dest: /etc/ssh/sshd_config.d/
27+
owner: root
28+
group: root
29+
mode: '0644'
30+
31+
32+
- name: Remove all files in /etc/ssh/ssh_config.d but keep the directory
33+
ansible.builtin.find:
34+
paths: /etc/ssh/ssh_config.d/
35+
file_type: file
36+
register: files_to_remove
37+
38+
- name: Delete files in /etc/ssh/ssh_config.d
39+
ansible.builtin.file:
40+
path: "{{ item.path }}"
41+
state: absent
42+
loop: "{{ files_to_remove.files }}"
43+
44+
- name: Ensure /etc/ssh/ssh_config.d/ directory exists
45+
ansible.builtin.file:
46+
path: /etc/ssh/ssh_config.d/
47+
state: directory
848
owner: root
949
group: root
10-
notify: reload sshd
50+
mode: '0755'
1151

12-
- name: authentication | ssh_config
13-
template:
14-
src: "ssh_config.j2"
15-
dest: "/etc/ssh/ssh_config"
16-
mode: 0644
52+
- name: Copy ssh_config to /etc/ssh/ssh_config.d/
53+
ansible.builtin.copy:
54+
src: "ssh_config.conf"
55+
dest: /etc/ssh/ssh_config.d/
1756
owner: root
1857
group: root
58+
mode: '0644'

0 commit comments

Comments
 (0)