Change SSH port in Debian

Exposing a server to the internet might be pretty scary. You would like to limit the number of exposed services to a minimum. Probably the most powerful service on any Linux machine would be the ssh server. With it you can control the computer and let it perform literally any task. If you want to be able to control your Linux based computer, from any place on the internet you may want to guard yourself against unauthorized access.

Changing the port

Open /etc/ssh/ssh_config file, and find the line "Ports". By default, it's commented out (has a # in the beginning of the line), meaning it falls back to default port 22.

Uncomment that line and set another port number (ideally greater than 1024, but lower than 65536). Check if the new port does not conflict with any of your already used service ports. A list of commonly used services' ports can be found here.

After saving, restart the ssh service:

sudo systemctl restart sshd

Check Before You Disconnect!

Don't disconnect from your terminal yet! Check, with a second terminal, whether the new setup actually works. If it doesn't you'll still have the chance to fix it with your already existing terminal.

If you do lock yourself out you can always still login directly using the console. However that will be rather difficult on a remote machine.

Previous Post Next Post