Changing the Default SSH Port

1. Log on to the server as an administrator.

2. Open the SSH configuration file sshd_config with the text editor vi:

1
vi /etc/ssh/sshd_config

3. Search for the entry Port 22.

4. Replace port 22 with a port between 1024 and 65536.

5. Save the file.

6. Restart the service.

Ubuntu

1
service ssh restart

CentOS7

1
systemctl restart sshd

To establish an SSH connection after this change, enter the following command:

1
ssh root@IP_address_of_the_server -p NewPort

7. Set up automatic startup

1
systemctl enable ssh

Changing the Default SSH Port
https://www.hardyhu.cn/2022/02/21/Changing-the-Default-SSH-Port/
Author
John Doe
Posted on
February 21, 2022
Licensed under