Prerequisites
- Root/sudo access
- Firewall configured to allow new port
Step 1: Edit SSH Configuration
sudo nano /etc/ssh/sshd_configStep 2: Change Port
Find the line #Port 22 and change to:
Port 2222Step 3: Update Firewall
sudo ufw allow 2222/tcp
sudo ufw delete allow 22/tcp (after testing)Step 4: Restart SSH
sudo systemctl restart sshd⚠️ Keep the original SSH session open while testing the new port to avoid lockout.