To change the SSH port:
-
Log on to the server as an administrator.
-
Open the SSH configuration file sshd_config with the text editor vi:
vi /etc/ssh/sshd_config -
Search for the entry Port 22.
-
Replace port 22 with a port between 1024 and 65536.
-
Save the file.
-
Restart the service.
Ubuntu
service ssh restart
CentOS 7
systemctl restart sshd
To establish an SSH connection after this change, enter the following command:
ssh root@IP_address_of_the_server -p NewPort