Please refer to the following steps to change the SSH port in Ubuntu.
- Login to your server via SSH.
- Open the sshd_config file using the below command.
# sudo nano /etc/ssh/sshd_config
- Check the line which starts with #port 22. We will need to uncomment this line and change the port number to your desired port number. From the default port 22 to port 232.
- Save the changes that you have made and exit from the file. Now, you will have to reload the file by performing the following command.
# sudo systemctl reload sshd
- To make sure that everything is working fine or not, you will need to log out the current session and try to login with the new SSH port below format.
ssh [email protected]_ip_address -p port
That’s it you have successfully changed your SSH port.