Changed SSHD port in VPS can't login

I altered the SSHD port on my unmanaged CentOS VPS to 0062, now I am unable to SSH in and get the error: Network error: connection refused.

Does anyone know how to get in and fix this? And why changing the port to this has stopped me from connecting?

Note: The VPS is hosted externally


A number of things could of have happened. A few things come to mind:

  • Your firewall is still blocking the connection.
  • Another service is running on port 62
  • You did not restart the service after changing the value
  • ...

Try connecting via the out-of-band console (if you have one) and alter what needs to be changed (firewall, settings, ...). To test wether or not your firewall is bugging you, stop it for a little while and see if you can get in (service iptables stop)

I'm also not sure about putting 0062 as a port. You might need to put 62 instead.

If you are unable to get into the out-of-band, ask your provider to have a look. Otherwise, you will have to reimage the machine.

The script should indeed change both the port on the firewall and in the config for ssh:

sed -i 's/#HostKey \/etc\/ssh\/ssh_host_rsa_key/HostKey \/etc\/ssh\/ssh_host_rsa_key/g' /etc/ssh/sshd_config
sed -i 's/#HostKey \/etc\/ssh\/ssh_host_dsa_key/HostKey \/etc\/ssh\/ssh_host_dsa_key/g' /etc/ssh/sshd_config
sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/g' /etc/ssh/sshd_config
sed -i 's/#RSAAuthentication/RSAAuthentication/g' /etc/ssh/sshd_config
sed -i 's/#AuthorizedKeysFile/AuthorizedKeysFile/g' /etc/ssh/sshd_config
sed -i 's/#IgnoreRhosts yes/IgnoreRhosts yes/g' /etc/ssh/sshd_config
sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/g' /etc/ssh/sshd_config

/usr/sbin/sshd -t

service sshd restart

iptables -I INPUT -p tcp --dport $PORTNUM -j ACCEPT

service iptables restart

However, the 0062 might of have b0rked one or maybe both of them. Try getting back into your machine first.


0062 could be interpreted as octal...which would be port 50. Try connecting on port 50. I doubt it will work, but worth a try.

Who is the VPS hosted with? Most of them give you either a web console which doesn't connect via SSH, or at least a way to boot your system from a rescue CD where you could go in and change the config file.