To change the default SSH port, the first thing you want to do is backup the current SSH configuration file on your system. To do that, run the commands below.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
This creates a new named
sshd_config.bak with the current settings of the sshd_config file. If something goes wrong, you can then restore the file from the backup.
Next, run the commands below to open the default SSH configuration file
# nano /etc/ssh/sshd_config
Run ssh on a non-standard port # 2022 using Port option
Set Port for example to 2022:
Save and close the file.
Then restart the SSH service.
service sshd reload
if your have firewall system installed on your server, you must allow incoming and outgoing data in the new port. So you should add your new port in “TCP_IN” and “TCP_OUT”.