Ssh – How to work out which port to log in on with SSH

sshtcp

I have an Ubuntu 10.04 server setup remotely that I setup a while back. While I recorded the username and password, I seem to have been clever and changed the usual ssh port from 22 to… something else.

How do I find out what that port might be?

I do have access to the server via the hosting company's back door, so I can execute whatever Unix commands are needed – but I cannot log in using a normal putty shell on my machine.

Best Answer

First check on the config file which port is configured:

$ sudo grep Port /etc/ssh/sshd_config
Port 22

Then either restart ssh to make sure it loads the config you just saw or find out on which port ssh is running:

$ sudo netstat -tpln | egrep '(Proto|ssh)'
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      12586/sshd

That's a normal ssh running on port 22.

Related Question