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 am having an issue with SSH.

ssh: connect to host port 22: Connection refused

I get the above error whenever I try to connect my desktop with another desktop using SSH, but I'm able to ping the other desktop successfully.

ssh: connect to host port 22: Connection refused

When I attempt to restart sshd, it outputs the following error

sshd : unrecognized service

I can connect to remote server using SSH, but I'm not able to connect within the local network. Please help me solve this issue.

share|improve this question
Please provide the command line you are using, or the application. Also add the Ubuntu version. Are these two desktops on the same LAN (local network)? – david6 Feb 13 '13 at 7:42
How are you trying to start the ssh daemon? You should be using sudo service ssh start. If that doesn't work, could you post the output of ls -l /etc/init/ssh.conf ? – Jeremy Kerr Feb 13 '13 at 7:43
@david6, if they weren't on the same LAN, then the connection would just fail or be blackhole'd. He's getting a refused connection which means that a computer saw the request and sent back a refusal. – Nathan J. Brauer Feb 13 '13 at 9:18
Im using Ubuntu 12.10, where I need to ssh to another computer within the same local network. But, I'm able to connect to a remote server in another network. Please help me... – Rudra Feb 13 '13 at 9:19
Confirm if you are using a firewall. Is SSH server installed on each target host? – david6 Feb 13 '13 at 10:39

Try un-installing and then installing openssh-server:

sudo apt-get remove openssh-client openssh-server

and then

sudo apt-get install openssh-client openssh-server

This worked for me. If you still can not connect, try

sudo ufw status verbose

and let us know what the output is.

share|improve this answer
I am having the same problem and the output of sudo ufw status verbose is status: inactive , so I enabled it but the error persists, this is the new output Status: active Logging: off Default: deny (incoming), allow (outgoing) New profiles: skip To Action From -- ------ ---- 22 ALLOW IN Anywhere 22 ALLOW IN Anywhere (v6) – Nishant Nov 25 '14 at 14:26

First make sure that ssh service running on or is possible that system doesn't have an SSH daemon, so you need to install ssh on that system.

sudo apt-get install openssh-server

If it's already installed, run sudo service ssh restart, then comment here with the output of this command from both the systems.

share|improve this answer
When I restart the ssh it stops first and starts with a PID no. – Rudra Feb 13 '13 at 9:20

In my installation of Ubuntu 14.04 LTS desktop edition from the Ubuntu website, openssh-server is not installed by default. BIG FAT THUMBS DOWN Canonical!!!!! The installation is relatively easy and has been mentioned already by other answers above:

sudo apt-get update && sudo apt-get upgrade && sudo apt-get install openssh-server

share|improve this answer
Many people don't use ssh. I think it's alright to not include the server by default on the desktop edition. – prakharsingh95 May 9 '15 at 7:43

Check to make sure your router either, can accept ssh or has it enabled somewhere in the settings. Sometimes something this simple can be overlooked.

share|improve this answer
  1. Goto vim /etc/ssh/sshd_config

  2. Change the Authentication "PermitRootLogin" to "yes"


    PermitRootLogin yes
  3. service sshd restart

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.