Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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!

share|improve this question
Can you post your ssh /etc/ssh/ssh_config on pastebin ( and edit you question to contain the link? – con-f-use Oct 17 '12 at 8:37
Stop the sshd service and run the sshd in standalone debug mode: /usr/sbin/sshd -p 22 -D -d -e. Try connecting and see what happens. – phoibos Oct 17 '12 at 8:48
Glad that it worked! Please remove your answer since you posted the information in your post and accept my answer to mark the question as solved. – phoibos Oct 17 '12 at 10:49
if this is happening in all users, make sure you are following this doc especially check this doc, the part about /etc/ssh/ssh_host_dsa_key in this doc…. – JimLohse Feb 7 at 4:24
up vote 8 down vote accepted

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.

share|improve this answer

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; posting it here for benefit of others.

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

Because 'Match blocks' need to be at the end of the sshd_config file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.