Change Default SSH Port to Prevent Attacks
By default, SSH runs on port 22
, which is the primary target for automated brute-force attacks. Changing this port adds an extra layer of protection against malicious attempts.
Step 1: Open SSH Configuration File
sudo nano /etc/ssh/sshd_config
Step 2: Change SSH Port
Find the line:
#Port 22
Uncomment and change it to another port, e.g.:
Port 2222
Step 3: Adjust Firewall Rules
Allow the new port in your firewall:
sudo ufw allow 2222/tcp
Step 4: Restart SSH
sudo systemctl restart ssh
✅ From now on, connect to your server using the new port:
ssh -p 2222 user@your-server-ip