Skip to main content
The SSH daemon listens on port 22 by default. Follow these steps to change it.
1

Log in to the server

Log in via SSH.
2

Open the SSH configuration file

3

Update the Port line

Find the Port line and replace the value 22 with the new port number. If the line begins with #, remove the # to uncomment it first.
sshd_config with Port 22 commented out
sshd_config with Port 2233
4

Save and close the file

Press Ctrl+O, then Enter to confirm the filename, and Ctrl+X to exit nano.
5

Restart the SSH service

On Ubuntu and Debian:
On CentOS, AlmaLinux, and Rocky Linux:
On FreeBSD:
6

Allow traffic on the new port

On Ubuntu and Debian (ufw):
On CentOS, AlmaLinux, and Rocky Linux (firewalld):
Replace 2233 with the chosen port number.
7

Verify the port is reachable

From a local machine (not from the server), run:
Replace <server_ip> with the server IP address and 2233 with the chosen port. A successful response includes the SSH banner line starting with SSH-2.0.
Telnet output showing SSH banner on port 2233
8

Test the SSH connection

Keep the current SSH session open. Open a separate terminal window and connect using the new port:
Replace username with the server username (typically root) and <server_ip> with the server IP address. If the connection fails, revert the Port value in /etc/ssh/sshd_config back to 22 and restart the SSH service again.