1212# ===================
1313
1414# Either disable or only allow root login via certificates.
15- <% if @node['ssh-hardening']['ssh']['allow_root_with_key'] %>
15+ <% if @node['ssh-hardening']['ssh']['server'][' allow_root_with_key'] %>
1616PermitRootLogin without-password
1717<% else %>
1818PermitRootLogin no
@@ -27,12 +27,12 @@ Port <%= ssh_port %>
2727AddressFamily <%= ((@node['ssh-hardening']['network']['ipv6']['enable']) ? "any" : "inet" ) %>
2828
2929# 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.
30- <% Array(@node['ssh-hardening']['ssh']['listen_to']).each do |ssh_ip| %>
30+ <% Array(@node['ssh-hardening']['ssh']['server'][' listen_to']).each do |ssh_ip| %>
3131ListenAddress <%= ssh_ip %>
3232<% end %>
3333
3434# List HostKeys here.
35- <% Array(@node['ssh-hardening']['ssh']['host_key_files']).each do |host_key_file| %>
35+ <% Array(@node['ssh-hardening']['ssh']['server'][' host_key_files']).each do |host_key_file| %>
3636HostKey <%= host_key_file %> # Req 20
3737<% end %>
3838
@@ -88,9 +88,9 @@ KexAlgorithms <%= @kex %>
8888UseLogin no
8989UsePrivilegeSeparation <%= @use_priv_sep %>
9090PermitUserEnvironment no
91- LoginGraceTime <%= @node['ssh-hardening']['ssh']['login_grace_time'] %>
92- MaxAuthTries <%= @node['ssh-hardening']['ssh']['max_auth_tries'] %>
93- MaxSessions <%= @node['ssh-hardening']['ssh']['max_sessions'] %>
91+ LoginGraceTime <%= @node['ssh-hardening']['ssh']['server'][' login_grace_time'] %>
92+ MaxAuthTries <%= @node['ssh-hardening']['ssh']['server'][' max_auth_tries'] %>
93+ MaxSessions <%= @node['ssh-hardening']['ssh']['server'][' max_sessions'] %>
9494MaxStartups 10:30:100
9595
9696# Enable public key authentication
@@ -102,12 +102,12 @@ IgnoreUserKnownHosts yes
102102HostbasedAuthentication no
103103
104104# Enable PAM to enforce system wide rules
105- UsePAM <%= ((@node['ssh-hardening']['ssh']['use_pam']) ? "yes" : "no" ) %>
105+ UsePAM <%= ((@node['ssh-hardening']['ssh']['server'][' use_pam']) ? "yes" : "no" ) %>
106106# Disable password-based authentication, it can allow for potentially easier brute-force attacks.
107107<% passsword_auth = @node['ssh-hardening']['ssh']['server']['password_authentication'] || !!@node['ssh-hardening']['ssh']['password_authentication'] -%>
108108PasswordAuthentication <%= (passsword_auth ? "yes" : "no" ) %>
109109PermitEmptyPasswords no
110- ChallengeResponseAuthentication <%= (@node['ssh-hardening']['ssh']['challenge_response_authentication'] ? "yes" : "no" ) %>
110+ ChallengeResponseAuthentication <%= (@node['ssh-hardening']['ssh']['server'][' challenge_response_authentication'] ? "yes" : "no" ) %>
111111
112112# Only enable Kerberos authentication if it is configured.
113113KerberosAuthentication no
@@ -120,23 +120,23 @@ GSSAPIAuthentication no
120120GSSAPICleanupCredentials yes
121121
122122# In case you don't use PAM (`UsePAM no`), you can alternatively restrict users and groups here. For key-based authentication this is not necessary, since all keys must be explicitely enabled.
123- <% unless @node['ssh-hardening']['ssh']['deny_users'].empty? %>
124- DenyUsers <%= @node['ssh-hardening']['ssh']['deny_users'].join(' ') %>
123+ <% unless @node['ssh-hardening']['ssh']['server'][' deny_users'].empty? %>
124+ DenyUsers <%= @node['ssh-hardening']['ssh']['server'][' deny_users'].join(' ') %>
125125<% else %>
126126#DenyUsers *
127127<% end %>
128- <% unless @node['ssh-hardening']['ssh']['allow_users'].empty? %>
129- AllowUsers <%= @node['ssh-hardening']['ssh']['allow_users'].join(' ') %>
128+ <% unless @node['ssh-hardening']['ssh']['server'][' allow_users'].empty? %>
129+ AllowUsers <%= @node['ssh-hardening']['ssh']['server'][' allow_users'].join(' ') %>
130130<% else %>
131131#AllowUsers user1
132132<% end %>
133- <% unless @node['ssh-hardening']['ssh']['deny_groups'].empty? %>
134- DenyGroups <%= @node['ssh-hardening']['ssh']['deny_groups'].join(' ') %>
133+ <% unless @node['ssh-hardening']['ssh']['server'][' deny_groups'].empty? %>
134+ DenyGroups <%= @node['ssh-hardening']['ssh']['server'][' deny_groups'].join(' ') %>
135135<% else %>
136136#DenyGroups *
137137<% end %>
138- <% unless @node['ssh-hardening']['ssh']['allow_groups'].empty? %>
139- AllowGroups <%= @node['ssh-hardening']['ssh']['allow_groups'].join(' ') %>
138+ <% unless @node['ssh-hardening']['ssh']['server'][' allow_groups'].empty? %>
139+ AllowGroups <%= @node['ssh-hardening']['ssh']['server'][' allow_groups'].join(' ') %>
140140<% else %>
141141#AllowGroups group1
142142<% end %>
@@ -149,61 +149,61 @@ AllowGroups <%= @node['ssh-hardening']['ssh']['allow_groups'].join(' ') %>
149149TCPKeepAlive no
150150
151151# Manage `ClientAlive..` signals via interval and maximum count. This will periodically check up to a `..CountMax` number of times within `..Interval` timeframe, and abort the connection once these fail.
152- ClientAliveInterval <%= @node['ssh-hardening']['ssh']['client_alive_interval'] %>
153- ClientAliveCountMax <%= @node['ssh-hardening']['ssh']['client_alive_count'] %>
152+ ClientAliveInterval <%= @node['ssh-hardening']['ssh']['server'][' client_alive_interval'] %>
153+ ClientAliveCountMax <%= @node['ssh-hardening']['ssh']['server'][' client_alive_count'] %>
154154
155155# Disable tunneling
156156PermitTunnel no
157157
158158# Disable forwarding tcp connections.
159159# no real advantage without denied shell access
160- AllowTcpForwarding <%= ((@node['ssh-hardening']['ssh']['allow_tcp_forwarding']) ? 'yes' : 'no' ) %>
160+ AllowTcpForwarding <%= ((@node['ssh-hardening']['ssh']['server'][' allow_tcp_forwarding']) ? 'yes' : 'no' ) %>
161161
162162# Disable agent formwarding, since local agent could be accessed through forwarded connection.
163163# no real advantage without denied shell access
164- AllowAgentForwarding <%= ((@node['ssh-hardening']['ssh']['allow_agent_forwarding']) ? 'yes' : 'no' ) %>
164+ AllowAgentForwarding <%= ((@node['ssh-hardening']['ssh']['server'][' allow_agent_forwarding']) ? 'yes' : 'no' ) %>
165165
166166# Do not allow remote port forwardings to bind to non-loopback addresses.
167167GatewayPorts no
168168
169169# Disable X11 forwarding, since local X11 display could be accessed through forwarded connection.
170- X11Forwarding <%= ((@node['ssh-hardening']['ssh']['allow_x11_forwarding']) ? 'yes' : 'no' ) %>
170+ X11Forwarding <%= ((@node['ssh-hardening']['ssh']['server'][' allow_x11_forwarding']) ? 'yes' : 'no' ) %>
171171X11UseLocalhost yes
172172
173173
174174# Misc. configuration
175175# ===================
176176
177177
178- PrintMotd <%= ((@node['ssh-hardening']['ssh']['print_motd']) ? 'yes' : 'no' ) %>
179- PrintLastLog <%= ((@node['ssh-hardening']['ssh']['print_last_log']) ? 'yes' : 'no' ) %>
180- Banner <%= @node['ssh-hardening']['ssh']['banner'] ? @node['ssh-hardening']['ssh']['banner'] : 'none' %>
178+ PrintMotd <%= ((@node['ssh-hardening']['ssh']['server'][' print_motd']) ? 'yes' : 'no' ) %>
179+ PrintLastLog <%= ((@node['ssh-hardening']['ssh']['server'][' print_last_log']) ? 'yes' : 'no' ) %>
180+ Banner <%= @node['ssh-hardening']['ssh']['server'][' banner'] ? @node['ssh-hardening']['ssh']['server ']['banner'] : 'none' %>
181181
182182<% if @node['platform_family'] == 'debian' %>
183- DebianBanner <%= @node['ssh-hardening']['ssh']['os_banner'] ? 'yes' : 'no' %>
183+ DebianBanner <%= @node['ssh-hardening']['ssh']['server'][' os_banner'] ? 'yes' : 'no' %>
184184<% end %>
185185
186- <% if @node['ssh-hardening']['ssh']['use_dns'].nil? %>
186+ <% if @node['ssh-hardening']['ssh']['server'][' use_dns'].nil? %>
187187# Since OpenSSH 6.8, this value defaults to 'no'
188188#UseDNS no
189189<% else %>
190- UseDNS <%= ((@node['ssh-hardening']['ssh']['use_dns']) ? 'yes' : 'no' ) %>
190+ UseDNS <%= ((@node['ssh-hardening']['ssh']['server'][' use_dns']) ? 'yes' : 'no' ) %>
191191<% end %>
192192#PidFile /var/run/sshd.pid
193193#MaxStartups 10
194194#ChrootDirectory none
195195#ChrootDirectory /home/%u
196196
197- <% if @node['ssh-hardening']['ssh']['sftp']['enable'] %>
197+ <% if @node['ssh-hardening']['ssh']['server'][' sftp']['enable'] %>
198198# Configuration, in case SFTP is used
199199## override default of no subsystems
200200## Subsystem sftp /opt/app/openssh5/libexec/sftp-server
201201Subsystem sftp internal-sftp -l VERBOSE
202202
203203## These lines must appear at the *end* of sshd_config
204- Match Group <%= @node['ssh-hardening']['ssh']['sftp']['group'] %>
204+ Match Group <%= @node['ssh-hardening']['ssh']['server'][' sftp']['group'] %>
205205ForceCommand internal-sftp -l VERBOSE
206- ChrootDirectory <%= @node['ssh-hardening']['ssh']['sftp']['chroot'] %>
206+ ChrootDirectory <%= @node['ssh-hardening']['ssh']['server'][' sftp']['chroot'] %>
207207AllowTcpForwarding no
208208AllowAgentForwarding no
209209PasswordAuthentication no
0 commit comments