11

I am having an issue with SSH.

ssh: connect to host 192.168.1.7 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 192.168.1.7 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. How can I solve this issue?

  • 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
  • 1
    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.B. 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
14

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.

  • 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
6

First make sure that ssh service running on 192.168.1.7 or not..it 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.

  • When I restart the ssh it stops first and starts with a PID no. – Rudra Feb 13 '13 at 9:20
  • Thank you this seems to be precisely the case for me... openssh-server had to be installed on the target machine. – Br. Sayan Jun 13 '17 at 11:40
0

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

  • 1
    Many people don't use ssh. I think it's alright to not include the server by default on the desktop edition. – ps95 May 9 '15 at 7:43
0

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.

0
  1. Goto vim /etc/ssh/sshd_config

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

    Eg:

    Authentication:
    
    PermitRootLogin yes
    
  3. service sshd restart

0

Check if you have SSH server installed:

dpkg -l openssh-server

If not, install it:

sudo apt update && sudo apt install -y ssh

Now check if your 22 port is in use:

netstat -atn | grep :22

protected by Zanna Jan 21 at 9:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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