LKBEN11147: Howto change the ssh port to a different one


To make it more difficult for script kiddies to try lots of passwords you can opt for changing the ssh port otherwise log are full of break-in messages




To change your ssh port you should edit /etc/ssh/sshd_config and change the line containing Port 22 to e.g. Port 33212. The number you change your port on can be taken at random but should be smaller than 54536 and I would not use a well know port. You can change this over a ssh session which will stay even if you restart the services or daemon. You should not close this connection unless you are shure your new settings work!

On debian you can use

invoke-rc.d ssh restart

to activate the new changes. You can make a connection on your new port to check if everything works fine. If it does not, you can still take your changes back! By connection on the new port, a new ssh-key will be generated! So be carefull when you configured your system to only connect with public and private keys! (you should generate and distribute your keys first!) You can also check your old port, which is 22 by default. This will not work anymore, although the old connection is still working, you cannot make a new session on this port!


The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.