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_config
or/etc/ssh/sshd_config
and 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
ssh
version 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
ssh
servicesudo systemctl restart ssh
orsudo 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)