Skip to content
This repository was archived by the owner on Dec 26, 2020. It is now read-only.

Commit 936f6c2

Browse files
committed
Merge branch 'master' of github.com:hardening-io/ansible-ssh-hardening into update-common
2 parents 00e652b + 9502103 commit 936f6c2

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

roles/ansible-ssh-hardening/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ssh_listen_to: ['0.0.0.0'] # sshd
2929
# Host keys to look for when starting sshd.
3030
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key'] # sshd
3131

32+
# Specifies the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged.
33+
ssh_max_auth_retries: 2
34+
3235
ssh_client_alive_interval: 600 # sshd
3336
ssh_client_alive_count: 3 # sshd
3437
# one or more hosts, to which ssh-client can connect to. Default is empty, but should be configured for security reasons!

roles/ansible-ssh-hardening/templates/openssh.conf.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
# ===================
1010

1111
# Address family should always be limited to the active network configuration.
12-
AddressFamily {% if network_ipv6_enable -%}any{% else -%}inet{% endif %}
13-
12+
AddressFamily {{ 'any' if network_ipv6_enable else 'inet' }}
1413
# Restrict the following configuration to be limited to this Host.
1514
{% for host in ssh_remote_hosts -%}
1615
Host {{host}}

roles/ansible-ssh-hardening/templates/opensshd.conf.j2

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99
# ===================
1010

1111
# Either disable or only allow root login via certificates.
12-
{% if ssh_allow_root_with_key -%}
13-
PermitRootLogin without-password
14-
{% else %}
15-
PermitRootLogin no
16-
{% endif %}
12+
PermitRootLogin {{ 'without-password' if ssh_allow_root_with_key else 'no' }}
1713

1814
# Define which port sshd should listen to. Default to `22`.
1915
{% for port in ssh_ports -%}
2016
Port {{port}}
2117
{% endfor %}
2218

2319
# Address family should always be limited to the active network configuration.
24-
AddressFamily {% if network_ipv6_enable -%}any{% else %}inet{% endif %}
20+
AddressFamily {{ 'any' if network_ipv6_enable else 'inet' }}
2521

2622
# Define which addresses sshd should listen to. Default to `0.0.0.0`, ie make sure you put your desired address in here, since otherwise sshd will listen to everyone.
2723
{% for address in ssh_listen_to -%}
@@ -125,7 +121,7 @@ UsePrivilegeSeparation {% if (ansible_distribution == 'Debian' and ansible_distr
125121

126122
PermitUserEnvironment no
127123
LoginGraceTime 30s
128-
MaxAuthTries 2
124+
MaxAuthTries {{ssh_max_auth_retries}}
129125
MaxSessions 10
130126
MaxStartups 10:30:100
131127

@@ -138,7 +134,7 @@ IgnoreUserKnownHosts yes
138134
HostbasedAuthentication no
139135

140136
# Enable PAM to enforce system wide rules
141-
UsePAM {% if ssh_use_pam -%}yes{% else %}no{% endif %}
137+
UsePAM {{ 'yes' if ssh_use_pam else 'no' }}
142138

143139
# Disable password-based authentication, it can allow for potentially easier brute-force attacks.
144140
PasswordAuthentication no
@@ -187,11 +183,11 @@ PermitTunnel no
187183

188184
# Disable forwarding tcp connections.
189185
# no real advantage without denied shell access
190-
AllowTcpForwarding {% if ssh_allow_tcp_forwarding -%}yes{% else %}no{% endif %}
186+
AllowTcpForwarding {{ 'yes' if ssh_allow_tcp_forwarding else 'no' }}
191187

192188
# Disable agent formwarding, since local agent could be accessed through forwarded connection.
193189
# no real advantage without denied shell access
194-
AllowAgentForwarding {% if ssh_allow_agent_forwarding -%}yes{% else %}no{% endif %}
190+
AllowAgentForwarding {{ 'yes' if ssh_allow_agent_forwarding else 'no' }}
195191

196192
# Do not allow remote port forwardings to bind to non-loopback addresses.
197193
GatewayPorts no
@@ -204,9 +200,9 @@ X11UseLocalhost yes
204200
# Misc. configuration
205201
# ===================
206202

207-
PrintMotd {% if ssh_print_motd -%}yes{% else %}no{% endif %}
203+
PrintMotd {{ 'yes' if ssh_print_motd else 'no' }}
208204

209-
PrintLastLog {% if ssh_print_last_log -%}yes{% else %}no{% endif %}
205+
PrintLastLog {{ yes if ssh_print_last_log else 'no' }}
210206

211207
#Banner /etc/ssh/banner.txt
212208
#UseDNS yes

0 commit comments

Comments
 (0)