Solution for “ssh: connect to host localhost port 22: Connection refused”


Hi friends,

Since three days, i had problem with my ssh connection. When i was tried to connect my laptop to others machine,  I’m able to connect with them. But when i tried to connect, others machine to my laptop, I got this Error.

[student@mercury ~]$ ssh suresh@192.168.1.9
ssh: connect to host 192.168.1.9 port 22: Connection refused

Solution for this “port 22: Connection refused” :

First check if sshd is running by trying the command ‘$ pgrep sshd
on the host. If the output is empty, its very likely that sshd is not
running. Try ‘tail -f /var/log/messages’ on one terminal and do
a ‘$ /etc/init.d/sshd start‘ on another terminal.  Then, check the
output that comes up on the previous terminal.

 

if PID comes, like 1702(any number), we conform the “sshd” is running.

Next, we have to flush the “iptables” by using the following command,

$ sudo iptables -F

That’s all. Now you can connect with anyone via ssh.

If again the same problem appear, Try ‘$ grep sshd /var/log/messages | tail‘ and
$ grep ssh /var/log/secure | tail‘ and check for any possible issues.

:)

 

About these ads

12 thoughts on “Solution for “ssh: connect to host localhost port 22: Connection refused”

    • Dear Theopaul,

      I think, you didn’t install “openssh-server” in your system. Which distro you are currently using? If you have any more doubts feel free to contact me :)

  1. please help….
    root@nagios-desktop:/# ssh localhost
    root@localhost’s password:
    Permission denied, please try again.
    root@localhost’s password:

    root@nagios-desktop:/#

  2. @valentin: If you did not find out yet, sshd is usually configured to block root login via ssh. So either allow it in /etc/ssh/sshd_config (insecure option) or ssh as a normal user and use sudo / su / sudo bash (depending on your distro).

  3. Hi Suresh,

    I install Cgywin and new to linux,…when i am giving ssh localhost command i got the same port 22 error and when i tried to give the “pgrep” command it gives me below error –
    – bash : pgrep : command not found

    please help.

  4. Pingback: ssh连不上vmware虚拟机ubuntu9.10 ubuntu10.10 | 罗生沙博客|java|开发工具|生活

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s