Hostxpeed
Login Get Started →
Security

How to Change SSH Port from 22

5 min read
30 views
Jun 10, 2026

Prerequisites

  • Root/sudo access
  • Firewall configured to allow new port

Step 1: Edit SSH Configuration

sudo nano /etc/ssh/sshd_config

Step 2: Change Port

Find the line #Port 22 and change to:

Port 2222

Step 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.

Was this article helpful?