Whenever deploying an Ubuntu server, accessing and managing it with SSH via LAN (Local Area Network) was never an issues.
But if you wanted to allow SSH access remotely or through Internet, then the standard port must be changed and the server must be protected behind a firewall.
1) To check existing SSH port :-
sudo cat /etc/ssh/sshd_config | grep Port |
2) To change the SSH port :-
sudo nano /etc/ssh/sshd_config |
Search for line --> #Port 22
Add a new line just below it with your preferred new SSH port --> Port [Your New SSH Port Number]
(eg. Port 9222)
3) Restart the SSH service :-
sudo systemctl restart sshd |
4) Also you might want to check UFW (if enabled) to have the specific port enabled :-
5) If the new port was not in the list, run the following command to ALLOW the access :-
6) Now you will need to DENY the access of common SSH port number 22 :-
7) Now you can test the connection of the new port and the old port to confirm the connection is properly configured. Also ensure the firewall also allows the newly created port pass-thru.
!!! HAPPY COMPUTING !!!