Disable root login
- Create new user
useradd -m username. - Set password
passwd username. -
Optional: Add user to sudoers
usermod -aG sudo username. - Edit
/etc/ssh/ssh_configor/etc/ssh/sshd_configand add:
# Authentication:
PermitRootLogin no
AllowUsers username
Might need to look for other config files being included that might override this setting (grep -r "PermitRootLogin" /etc/ssh/).
Harden SSH
- Disable empty password:
PermitEmptyPasswords no
- Limit the number of authentication tries per connection:
MaxAuthTries 3
- Changed to
sshversion 2:
Include /etc/ssh/sshd_config.d/*.conf
Protocol 2
Disable plain text authentication
- Connecting with SSH key:
UsePAM no
PasswordAuthentication no
ssh-keygen
Restart SSH service
- Restart
sshservicesudo systemctl restart sshorsudo systemctl restart sshd.
Prevent brute force attacks
- Install fail2ban or sshguard to ban IPs that fail to authenticate after a certain number of attempts.
Top comments (0)