ssh: connect to host myremotehost.com port 22: Connection refused

1,181

Solution 1

Your ISP may block connections to port 22 (nothing you or your router can do about it). Just set SSHd to run on a different port, e.g. 2222.

In /etc/ssh/sshd_config, change Port 22 to Port 2222 and then sudo service ssh restart. Port forward 2222 (or whatever), and try again.

Solution 2

Just to share. (might be with different configuration)

In my case, I found that that error can happen because I have not install openssh-server in the other machine.

After I install openssh-server in the other machine, the problem:

ssh: connect to host 192.168.XXX.XXX port 22: Connection refused

is solved.

Solution 3

  1. First check openssh-server installed in that system.

  2. check the status of ssh service, make ssh service start.

     sudo service ssh status    
     sudo service ssh start
    
  3. Check whether port 22 in that system is blocked by iptables. Just allow port in iptables and then check.

     sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
    
  4. Else change port number of ssh from 22 to 2222 by editing

     vi /etc/ssh/sshd_config         
     /etc/init.d/ssh restart.
    

Solution 4

I solved this problem by reinstalling openssh-server as follows:

sudo apt-get purge openssh-server 
sudo apt-get install openssh-server

Solution 5

Check the SSH service status and start the SSH service if it is stopped:

sudo service ssh status

In my case SSH was stopped, but after starting the service:

sudo service ssh start

I can be able to remote login to Linux.

Share:
1,181
IMMORTAL
Author by

IMMORTAL

Updated on September 18, 2022

Comments

  • IMMORTAL
    IMMORTAL about 1 year
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <AppXmlLogWritter>    
      <LogData>
        <LogID>5678201301211226306349434819061642515658</LogID>
        <LogDateTime>**20130121**122630</LogDateTime>
        <LogType>Warning</LogType>
        <LogFlag>PMLogFlag</LogFlag>
        <LogApplication>PMLogApplication</LogApplication>
        <LogModule>PMLogModule</LogModule>
        <LogLocation>PMLogLocation</LogLocation>
        <LogText>PMLogText</LogText>
      </LogData>
      <LogData>
        <LogID>5678201301211226306349434819063542617610</LogID>
        <LogDateTime>**20130121**122630</LogDateTime>
        <LogType>Warning</LogType>
        <LogFlag>PMLogFlag</LogFlag>
        <LogApplication>PMLogApplication</LogApplication>
        <LogModule>PMLogModule</LogModule>
        <LogLocation>PMLogLocation</LogLocation>
        <LogText>PMLogText</LogText>
      </LogData>
      <LogData>
        <LogID>5678201301211226306349434819065542731198</LogID>
        <LogDateTime>**20130121**122630</LogDateTime>
        <LogType>Warning</LogType>
        <LogFlag>PMLogFlag</LogFlag>
        <LogApplication>PMLogApplication</LogApplication>
        <LogModule>PMLogModule</LogModule>
        <LogLocation>PMLogLocation</LogLocation>
        <LogText>PMLogText</LogText>
      </LogData>
      <LogData>
        <LogID>5678201301211226306349434819067442849561</LogID>
        <LogDateTime>**20130117**122630</LogDateTime>
        <LogType>Warning</LogType>
        <LogFlag>PMLogFlag</LogFlag>
        <LogApplication>PMLogApplication</LogApplication>
        <LogModule>PMLogModule</LogModule>
        <LogLocation>PMLogLocation</LogLocation>
        <LogText>PMLogText</LogText>
      </LogData>
    </AppXmlLogWritter>
    

    From the above XmL file i want to read the xml document in between the range. such I implement the windows form with datetimepicker control for From Date and To Date and one submit button when i choose date from FROM DATE and also from the TO DATE it display the date into list view from these from tow different date for this i have write the code as

    private void btnSubmit_Click(object sender, EventArgs e)
            { 
     XmlElement objXmlRoot = objXmldoc.DocumentElement;
    if (chkBoxFromDate.Checked && chkBoxToDate.Checked)
                {
                    strXpathQuery = "/AppXmlLogWritter/LogData[LogDateTime >='" +  dateTimePickerFromDate.Value.ToString("yyyyMMdd") + "' and LogDateTime <='" + dateTimePickerToDate.Value.ToString("yyyyMMdd") + "']";
    }
    } 
    

    I use this query to display data but it shows me blank data.

  • bahudso
    bahudso over 11 years
    I still get the same connection refused error (22 when I don't specify a port when using ssh and 2222 when I use -p 222). I put incoming port 22 to forward to 2222 and changed the port to 2222 in sshd_config. Am I leaving out something?
  • ish
    ish over 11 years
    Just try this: Incoming 2222 on router has to forward to 2222 (with port 2222 set in sshd_config).
  • belacqua
    belacqua over 10 years
    This does not seem like a 'likely cause', especially given the accepted answer.
  • GTodorov
    GTodorov almost 6 years
    @izx kudos for the router rules. At some point I thought that I was freaking out and don't know what I'm doing. LOL!
  • Shashanth
    Shashanth about 5 years
    For future readers. Make sure that you are referring /etc/ssh/sshd_config (notice sshd) file. After pulling my hair for an hour I came to know this small difference. ;P
  • tudor -Reinstate Monica-
    tudor -Reinstate Monica- about 5 years
    My new router uses port 22 for it's remote administration feature and doesn't list it anywhere on the interface, so it may not necessarily be the ISP.
  • user227495
    user227495 over 3 years
    On client or server ? Sorry, I don't know much.
  • Ahwar
    Ahwar about 3 years
    I am using Google Cloud Shell and no matter what I try the error is the same.
  • Qazi Fahim Farhan
    Qazi Fahim Farhan about 3 years
    Thanks! It worked for me! This should be the accepted solution!
  • soheil zabihi
    soheil zabihi over 2 years
    On client......
  • Admin
    Admin over 1 year
    in my case ssh was failing while starting the service. This error was the output: sshd: no hostkeys available -- exiting and this was the fix: ssh-keygen -A