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.

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.
8
Test the SSH connection