How to change ssh port on linux server
One of the first things you should do, to set a layer of security to your linux server, is to change the default access port for ssh connection. It will avoid the automatic scripts that will try to login on your server but it’s not going to do much against a bad intended person.
To change the ssh port you need to edit the config file with your favorite editor. I personally use nano.
sudo nano /etc/ssh/sshd_config
Find the port line, uncomment it and change it to your desire. In this case the port will be 2222. I recommend not using ports lower than 1000.
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $nfig
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Save the new config and restart ssh service with the following command
sudo service sshd restart
Before disconnecting try the new settings. You will need to add the port parameter if you use terminal on linux mac or windows.
ssh user@server -p 2222
That’s it. Hope this will be helpful.