By default, SSH server opens 22 TCP port for incoming connections, and thus causes a potential threat of bruteforce attacks, because an intruder, having found such an open port on the server, tries to pick up the password to the remote server with the help of special automation tools.

Information about the port used is located on your virtual server (VPS) in the file sshd_config, which is located in the directory /etc/ssh/

To change SSH port:

Login to the server with the SSH client PuTTY

Check the list of open ports with the command:

netstat -tupln | grep LISTEN  

This way we check which ports are already in use so that we don't have to use them again.

After checking the ports we open the file sshd_config. You can open it with any text editor you have installed:

With the editor vi:*

vi /etc/ssh/sshd_config  

Edited by nano:

nano /etc/ssh/sshd_config  

Look for the sshd_config entry:

file

Change the port number to another port and save these changes with the command:

With the vi editor:*

:wq

Redited by nano:

CTRL+O  

After you press the Enter key on your keyboard to confirm

For the changes to take effect, restart the virtual SSH-server. This can be done by using the command:

/etc/init.d/ssh restart

or

/etc/init.d/sshd restart

Or

systemctl restart sshd.service  
Updated Nov. 10, 2024