Everyone knows 22 is the default SSH port. It’s always good to change the default SSH port and set it to something someone can’t even guess, which will save your system from usual hack attempts.
Here I’m going to change the port to 4242. Edit the main SSH configuration file.
vi /etc/ssh/sshd_config
You can find the below line.
#Port 22
Change it as below.
Port 4242
Restart SSH to update the changes.
/etc/init.d/sshd restart
You have changed the SSH port to 4242.
To login as “sshusr” from a remote Linux machine, you can run the below command.
ssh sshusr@IP/Hostname -p 4242
So that’s how you change the default SSH port.