Bizarre SSH Problem - It won't even start

I recently got Ubuntu 12.04 Precise, got it up and running with some MediaWiki software, static IP on the box and router and was able to access the main page even from a cell phone. Everything seemed great...

Then I wanted to finally get rid of the monitor and keyboard and login remotely via SSH.

I installed openssh-server, let everything point to port 22 for a test run and installed putty on my Windows XP machine. I got a connection refused. Went back and started checking the Ubuntu install itself... (I'm under root from this point on)

$ sudo -s

$ service ssh status
ssh stop/waiting

$ service ssh start
ssh start/running, process 2212

$ service ssh status
ssh stop/waiting

Apparently ssh has stopped or is waiting for something....

$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

I can't even connect to myself... I checked ufw (firewall) to see if port 22 is doing alright...

$ sudo ufw status
Status: active
To        Action        From
22        ALLOW         Anywhere
22/tcp    ALLOW         Anywhere
22        ALLOW         Anywhere (v6)
22/tcp    ALLOW         Anywhere (v6)

sshd_config shows only Port 22

Is ssh not using the right IP address at all? I just don't get what I did wrong here. When this is up and running I will def change the port number, but for now, I don't want to mess with the default install too much until a test run with putty is successful.

Edit:

Here are my sshd_config file and my ssh_config file.

The command /usr/sbin/sshd -p 22 -D -d -e returns:

/etc/ssh/sshd_config line 159: Subsystem 'sftp' already defined.

Edit: @phoibus moving the sshd_config file and reinstalling did the trick!

service ssh status

the above command shows that ssh is now running and I am now able to log in from my windows xp computer remotely via putty. Thanks so much! I can now use my monitor for other things!


Solution 1:

You got duplicate sections in your /etc/ssh/sshd_config file.

Rename your sshd_config file

sudo mv /etc/ssh/sshd_config /etc/ssh/sshd_config.old

and reinstall openssh-server to get the original file:

sudo apt-get install --reinstall openssh-server

See if it works now.

Solution 2:

My issue was also a setting issue, but I couldn't figure out which of my changes was the problem. After digging a little you can run sshd -t and any sshd_config errors will be reported.

root@sh1:/etc/ssh# sshd -t /etc/ssh/sshd_config line 102: Directive 'UsePAM' is not allowed within a Match block

Which means 'Match blocks' settings need to be at the end of the sshd_config file.