|
105 | 105 | when: "ubtu24cis_sshd_allow_users| default('') | length > 0 " |
106 | 106 | ansible.builtin.lineinfile: |
107 | 107 | path: /etc/ssh/sshd_config |
108 | | - regexp: '(?i)^(#|)\s*AllowUsers' |
| 108 | + regexp: '(?i)^(#?)\s*AllowUsers' |
109 | 109 | line: 'AllowUsers {{ ubtu24cis_sshd_allow_users }}' |
110 | 110 | validate: 'sshd -t -f %s' |
111 | 111 | notify: Restart sshd |
|
114 | 114 | when: "ubtu24cis_sshd_allow_groups| default('') | length > 0" |
115 | 115 | ansible.builtin.lineinfile: |
116 | 116 | path: /etc/ssh/sshd_config |
117 | | - regexp: '(?i)^(#|)\s*AllowGroups' |
| 117 | + regexp: '(?i)^(#?)\s*AllowGroups' |
118 | 118 | line: 'AllowGroups {{ ubtu24cis_sshd_allow_groups }}' |
119 | 119 | validate: 'sshd -t -f %s' |
120 | 120 | notify: Restart sshd |
|
123 | 123 | when: "ubtu24cis_sshd_deny_users| default('') | length > 0" |
124 | 124 | ansible.builtin.lineinfile: |
125 | 125 | path: /etc/ssh/sshd_config |
126 | | - regexp: '(?i)^(#|)\s*DenyUsers' |
| 126 | + regexp: '(?i)^(#?)\s*DenyUsers' |
127 | 127 | line: 'DenyUsers {{ ubtu24cis_sshd_deny_users }}' |
128 | 128 | validate: 'sshd -t -f %s' |
129 | 129 | notify: Restart sshd |
|
194 | 194 | line: "{{ item.line }}" |
195 | 195 | validate: 'sshd -t -f %s' |
196 | 196 | with_items: |
197 | | - - { regexp: '^ClientAliveInterval', line: 'ClientAliveInterval {{ ubtu24cis_sshd_client_alive_interval | default(ubtu24cis_sshd_default_client_alive_interval) }}' } |
198 | | - - { regexp: '^ClientAliveCountMax', line: 'ClientAliveCountMax {{ ubtu24cis_sshd_client_alive_count_max | default(ubtu24cis_sshd_default_client_alive_count_max) }}' } |
| 197 | + - { regexp: '^ClientAliveInterval', line: 'ClientAliveInterval {{ ubtu24cis_sshd_client_alive_interval }}' } |
| 198 | + - { regexp: '^ClientAliveCountMax', line: 'ClientAliveCountMax {{ ubtu24cis_sshd_client_alive_count_max }}' } |
199 | 199 | notify: Restart sshd |
200 | 200 |
|
201 | 201 | - name: "5.1.8 | PATCH | Ensure sshd DisableForwarding is enabled" |
|
209 | 209 | - sshd |
210 | 210 | ansible.builtin.lineinfile: |
211 | 211 | path: /etc/ssh/sshd_config |
212 | | - regexp: (?i)^(#|)\s*DisableForwarding |
| 212 | + regexp: (?i)^(#?)\s*DisableForwarding |
213 | 213 | line: 'DisableForwarding yes' |
214 | 214 | validate: 'sshd -t -f %s' |
215 | 215 | notify: Restart sshd |
|
229 | 229 | - sshd |
230 | 230 | ansible.builtin.lineinfile: |
231 | 231 | path: /etc/ssh/sshd_config |
232 | | - regexp: (?i)^(#|)\s*GSSAPIAuthentication |
| 232 | + regexp: (?i)^(#?)\s*GSSAPIAuthentication |
233 | 233 | line: 'GSSAPIAuthentication no' |
234 | 234 | validate: 'sshd -t -f %s' |
235 | 235 | notify: Restart sshd |
|
249 | 249 | - sshd |
250 | 250 | ansible.builtin.lineinfile: |
251 | 251 | path: /etc/ssh/sshd_config |
252 | | - regexp: (?i)^(#|)\s*HostbasedAuthentication |
| 252 | + regexp: (?i)^(#?)\s*HostbasedAuthentication |
253 | 253 | line: 'HostbasedAuthentication no' |
254 | 254 | validate: 'sshd -t -f %s' |
255 | 255 | notify: Restart sshd |
|
269 | 269 | - sshd |
270 | 270 | ansible.builtin.lineinfile: |
271 | 271 | path: /etc/ssh/sshd_config |
272 | | - regexp: (?i)^(#|)\s*IgnoreRhosts |
| 272 | + regexp: (?i)^(#?)\s*IgnoreRhosts |
273 | 273 | line: 'IgnoreRhosts yes' |
274 | 274 | validate: 'sshd -t -f %s' |
275 | 275 | notify: Restart sshd |
|
285 | 285 | - sshd |
286 | 286 | ansible.builtin.lineinfile: |
287 | 287 | path: /etc/ssh/sshd_config |
288 | | - regexp: (?i)^(#|)\s*KexAlgorithms |
289 | | - line: "KexAlgorithms {{ ubtu24cis_sshd_kex_algorithms | default(ubtu24cis_sshd_default_kex_algorithms) | join(',') }}" |
| 288 | + regexp: (?i)^(#?)\s*KexAlgorithms |
| 289 | + line: "KexAlgorithms {{ ubtu24cis_sshd_kex_algorithms | join(',') }}" |
290 | 290 | insertafter: '^# Ciphers and keying' |
291 | 291 | validate: 'sshd -t -f %s' |
292 | 292 | notify: Restart sshd |
|
302 | 302 | - sshd |
303 | 303 | ansible.builtin.lineinfile: |
304 | 304 | path: /etc/ssh/sshd_config |
305 | | - regexp: (?i)^(#|)\s*LoginGraceTime |
306 | | - line: 'LoginGraceTime {{ ubtu24cis_sshd_login_grace_time | default(ubtu24cis_sshd_default_login_grace_time) }}' |
| 305 | + regexp: (?i)^(#?)\s*LoginGraceTime |
| 306 | + line: 'LoginGraceTime {{ ubtu24cis_sshd_login_grace_time }}' |
307 | 307 | insertafter: '^# Authentication' |
308 | 308 | validate: 'sshd -t -f %s' |
309 | 309 | notify: Restart sshd |
|
321 | 321 | - sshd |
322 | 322 | ansible.builtin.lineinfile: |
323 | 323 | path: /etc/ssh/sshd_config |
324 | | - regexp: (?i)^(#|)\s*LogLevel |
325 | | - line: 'LogLevel {{ ubtu24cis_sshd_log_level | default(ubtu24cis_sshd_default_log_level) }}' |
| 324 | + regexp: (?i)^(#?)\s*LogLevel |
| 325 | + line: 'LogLevel {{ ubtu24cis_sshd_log_level }}' |
326 | 326 | insertafter: '^# Logging' |
327 | 327 | validate: 'sshd -t -f %s' |
328 | 328 | notify: Restart sshd |
|
342 | 342 | - sshd |
343 | 343 | ansible.builtin.lineinfile: |
344 | 344 | path: /etc/ssh/sshd_config |
345 | | - regexp: (?i)^(#|)\s*MACs |
346 | | - line: "MACs {{ ubtu24cis_sshd_macs | default(ubtu24cis_sshd_default_macs) | join(',') }}" |
| 345 | + regexp: (?i)^(#?)\s*MACs |
| 346 | + line: "MACs {{ ubtu24cis_sshd_macs | join(',')}}" |
347 | 347 | insertafter: '^# Ciphers and keying' |
348 | 348 | validate: 'sshd -t -f %s' |
349 | 349 | notify: Restart sshd |
|
359 | 359 | - sshd |
360 | 360 | ansible.builtin.lineinfile: |
361 | 361 | path: /etc/ssh/sshd_config |
362 | | - regexp: (?i)^(#|)\s*MaxAuthTries |
363 | | - line: 'MaxAuthTries {{ ubtu24cis_sshd_max_auth_tries | default(ubtu24cis_sshd_default_max_auth_tries) }}' |
| 362 | + regexp: (?i)^(#?)\s*MaxAuthTries |
| 363 | + line: 'MaxAuthTries {{ ubtu24cis_sshd_max_auth_tries }}' |
364 | 364 | insertafter: '^# Authentication' |
365 | 365 | validate: 'sshd -t -f %s' |
366 | 366 | notify: Restart sshd |
|
380 | 380 | - sshd |
381 | 381 | ansible.builtin.lineinfile: |
382 | 382 | path: /etc/ssh/sshd_config |
383 | | - regexp: (?i)^(#|)\s*MaxSessions |
384 | | - line: 'MaxSessions {{ ubtu24cis_sshd_max_sessions | default(ubtu24cis_sshd_default_max_sessions) }}' |
| 383 | + regexp: (?i)^(#?)\s*MaxSessions |
| 384 | + line: 'MaxSessions {{ ubtu24cis_sshd_max_sessions }}' |
385 | 385 | insertafter: '^# Authentication' |
386 | 386 | validate: 'sshd -t -f %s' |
387 | 387 | notify: Restart sshd |
|
401 | 401 | - sshd |
402 | 402 | ansible.builtin.lineinfile: |
403 | 403 | path: /etc/ssh/sshd_config |
404 | | - regexp: (?i)^(#|)\s*MaxStartups |
| 404 | + regexp: (?i)^(#?)\s*MaxStartups |
405 | 405 | line: 'MaxStartups 10:30:60' |
406 | 406 | validate: 'sshd -t -f %s' |
407 | 407 | notify: Restart sshd |
|
421 | 421 | - sshd |
422 | 422 | ansible.builtin.lineinfile: |
423 | 423 | path: /etc/ssh/sshd_config |
424 | | - regexp: (?i)^(#|)\s*PermitEmptyPasswords |
| 424 | + regexp: (?i)^(#?)\s*PermitEmptyPasswords |
425 | 425 | line: 'PermitEmptyPasswords no' |
426 | 426 | insertafter: '# To disable tunneled clear text passwords' |
427 | 427 | validate: 'sshd -t -f %s' |
|
438 | 438 | - sshd |
439 | 439 | ansible.builtin.lineinfile: |
440 | 440 | path: /etc/ssh/sshd_config |
441 | | - regexp: (?i)^(#|)\s*PermitRootLogin |
| 441 | + regexp: (?i)^(#?)\s*PermitRootLogin |
442 | 442 | line: 'PermitRootLogin no' |
443 | 443 | validate: 'sshd -t -f %s' |
444 | 444 | notify: Restart sshd |
|
458 | 458 | - sshd |
459 | 459 | ansible.builtin.lineinfile: |
460 | 460 | path: /etc/ssh/sshd_config |
461 | | - regexp: (?i)^(#|)\s*PermitUserEnvironment |
| 461 | + regexp: (?i)^(#?)\s*PermitUserEnvironment |
462 | 462 | line: 'PermitUserEnvironment no' |
463 | 463 | validate: 'sshd -t -f %s' |
464 | 464 | notify: Restart sshd |
|
479 | 479 | - pam |
480 | 480 | ansible.builtin.lineinfile: |
481 | 481 | path: /etc/ssh/sshd_config |
482 | | - regexp: (?i)^(#|)\s*UsePAM |
| 482 | + regexp: (?i)^(#?)\s*UsePAM |
483 | 483 | line: 'UsePAM yes' |
484 | 484 | insertafter: '^# and ChallengeResponseAuthentication' |
485 | 485 | validate: 'sshd -t -f %s' |
|
0 commit comments