Docs / Security / How to Change the SSH Port

How to Change the SSH Port

By Admin · Feb 25, 2026 · Updated Apr 24, 2026 · 517 views · 1 min read

Changing the default SSH port from 22 reduces automated brute-force attacks.

Choose a Port

Pick an unused port number between 1024 and 65535 (e.g., 2222).

Configure

Edit /etc/ssh/sshd_config:

Port 2222

Update Firewall

# UFW
ufw allow 2222/tcp
ufw delete allow 22/tcp

# firewalld
firewall-cmd --permanent --add-port=2222/tcp
firewall-cmd --permanent --remove-service=ssh
firewall-cmd --reload

Restart SSH

systemctl restart sshd

Test Before Disconnecting

Open a new terminal and connect on the new port:

ssh -p 2222 user@YOUR_IP_ADDRESS

Only close your current session after confirming the new port works.

Was this article helpful?