SSH Firewall – What to Do When Locked Out After Changing Port

firewallssh

I have a VPS where I changed the SSH port from the default 22. Unfortunately I forgot to allow the new port through the firewall. I don't have physical access to the server, and my host does not seem to offer any shell access to the VPS through their website. Result: I'm locked out of the server. Is there any way I can rectify this short of resetting the server?

Best Answer

If you made the changes by hand and reinvoked sshd resetting might help, but if you changed sshd_config then resetting the server will not help you, the server will come back up and listen on the new, firewalled, port.

You will have to access the VPS through a console or any other means your provider provides to rectify this kind of problem.

BTW, you can, and should, specify multiple ports in your sshd_config:

Port 22
Port 2222

that way you can test things on the new port before removing the old one, assuming you have to remove the old port in the first place. The only reason I ever had to setup sshd to listen to a different port is because a friend's internet provider blocks access to ports below 1025, and his router is not able to map ports, only to allow specific port traffic through, to an internal address.

Related Question