4 # Created by Wazuh, Inc. <ossec@wazuh.com>.
6 # This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2
10 $sshd_file=/etc/ssh/sshd_config;
14 # The option Port specifies on which port number ssh daemon listens for incoming connections.
15 # Changing the default port you may reduce the number of successful attacks from zombie bots, an attacker or bot doing port-scanning can quickly identify your SSH port.
16 [SSH Hardening - 1: Port 22 {PCI_DSS: 2.2.4}] [any] [1]
17 f:$sshd_file -> !r:^# && r:Port\.+22;
21 # The Protocol parameter dictates which version of the SSH communication and encryption protocols are in use.
22 # Version 1 of the SSH protocol has weaknesses.
23 [SSH Hardening - 2: Protocol 1 {PCI_DSS: 2.2.4}] [any] [2]
24 f:$sshd_file -> !r:^# && r:Protocol\.+1;
28 # The option PermitRootLogin specifies whether root can log in using ssh.
29 # If you want log in as root, you should use the option "Match" and restrict it to a few IP addresses.
30 [SSH Hardening - 3: Root can log in] [any] [3]
31 f:$sshd_file -> !r:^# && r:PermitRootLogin\.+yes;
32 f:$sshd_file -> r:^#\s*PermitRootLogin;
35 # PubkeyAuthentication yes
36 # Access only by public key
37 # Generally people will use weak passwords and have poor password practices. Keys are considered stronger than password.
38 [SSH Hardening - 4: No Public Key autentication {PCI_DSS: 2.2.4}] [any] [4]
39 f:$sshd_file -> !r:^# && r:PubkeyAuthentication\.+no;
40 f:$sshd_file -> r:^#\s*PubkeyAuthentication;
43 # PasswordAuthentication no
44 # The option PasswordAuthentication specifies whether we should use password-based authentication.
45 # Use public key authentication instead of passwords
46 [SSH Hardening - 5: Password Authentication {PCI_DSS: 2.2.4}] [any] [5]
47 f:$sshd_file -> !r:^# && r:PasswordAuthentication\.+yes;
48 f:$sshd_file -> r:^#\s*PasswordAuthentication;
51 # PermitEmptyPasswords no
52 # The option PermitEmptyPasswords specifies whether the server allows logging in to accounts with a null password
53 # Accounts with null passwords are a bad practice.
54 [SSH Hardening - 6: Empty passwords allowed {PCI_DSS: 2.2.4}] [any] [6]
55 f:$sshd_file -> !r:^# && r:PermitEmptyPasswords\.+yes;
56 f:$sshd_file -> r:^#\s*PermitEmptyPasswords;
60 # The option IgnoreRhosts specifies whether rhosts or shosts files should not be used in authentication.
61 # For security reasons it is recommended to no use rhosts or shosts files for authentication.
62 [SSH Hardening - 7: Rhost or shost used for authentication {PCI_DSS: 2.2.4}] [any] [7]
63 f:$sshd_file -> !r:^# && r:IgnoreRhosts\.+no;
64 f:$sshd_file -> r:^#\s*IgnoreRhosts;
68 # The option LoginGraceTime specifies how long in seconds after a connection request the server will wait before disconnecting if the user has not successfully logged in.
69 # 30 seconds is the recommended time for avoiding open connections without authenticate
70 [SSH Hardening - 8: Wrong Grace Time {PCI_DSS: 2.2.4}] [any] [8]
71 f:$sshd_file -> !r:^# && r:LoginGraceTime && !r:30\s*$;
72 f:$sshd_file -> r:^#\s*LoginGraceTime;
76 # The MaxAuthTries parameter specifices the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged.
77 # This should be set to 3.
78 [SSH Hardening - 9: Wrong Maximum number of authentication attempts {PCI_DSS: 2.2.4}] [any] [9]
79 f:$sshd_file -> !r:^# && r:MaxAuthTries && !r:3\s*$;
80 f:$sshd_file -> r:^#\s*MaxAuthTries;
81 f:$sshd_file -> !r:MaxAuthTries;