How
to change the SSH port in Linux and FreeBSD
This will show you how to change the SSH port in Linux and FreeBSD.
Firstly we need to modify the ssh configuration file named
/etc/ssh/sshd_config.
The location of the file is: /etc/ssh/sshd_config
You will need to open the file using your favorite text editor and
find the line:
#Port 22
The default port for SSH is 22 and # is there because the line is
commented. If you want to change this port you need simply to uncomment
the line deleting the # sign in front of it and if you want to change
it to 12134 for example the line should looks like this:
Port 12134
Once this is done you will need to restart the SSH daemon service. Here
is how it should be done:
In the most linux distribution you can do it using the command: root@somebox ~$
/etc/init.d/sshd restart
In FreeBSD this should be done using the command: root@somebox ~$
/etc/rc.d/sshd reload
Now you can login over SSH to the new port and the old one won't be
active for SSH connections anymore.