Nov 10, 2018

How to fix SSH server Problem on Ubuntu

Sometimes you encounter bizarre ssh server problem on Ubuntu.

When you check ssh service:

$ sudo service ssh status

It shows that "ssh start/running", but when you go to check whether the port is open, it didn't. SSH server actually didn't start.

Or sometimes it just shows you "ssh stop/waiting".

To fix this problem, Rename your sshd_config file

sudo mv /etc/ssh/sshd_config /etc/ssh/sshd_config.old
(or just remove it)

and reinstall openssh-server to get the original file:

sudo apt-get install --reinstall openssh-server

When ssh server really starts, it will show you the process id. And you can verify that process occupies your ssh port.

$ sudo service ssh start
ssh start/running, process 4803

$ sudo ps -ef | grep 4803

root      4803     1  0 17:39 ?        00:00:00 /usr/sbin/sshd -D

$ sudo netstat -nap | grep 22
tcp        0      0    *               LISTEN      4803/sshd  

$ sudo netstat -ap | grep ssh is much slower than number on my Ubuntu)
$ sudo netstat -ap | grep ssh
tcp        0      0 *:ssh                   *:*                     LISTEN      4803/sshd