CloudLinux.ro
Security

How to harden SSH: disable root login and change the port

Updated 7/20/2026

The root account is the number one target of attacks. Best practice: create a normal user with sudo, then forbid direct root login.

1. Create a sudo user

If you do not have one yet, see How to create a sudo user. Make sure you can log in with it before continuing.

2. Disable root login

In /etc/ssh/sshd_config:

PermitRootLogin no

3. Change the SSH port (optional)

Moving off port 22 reduces the noise from automated scans:

Port 2222

If you use UFW, allow the new port before restarting:

ufw allow 2222/tcp

4. Restart SSH

systemctl restart ssh

Do not close your current session until you have tested in a new terminal that you can connect with the new port and user.

Recommended

Combine with SSH keys and fail2ban for an SSH that is nearly impossible to break.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials