ssh: connect to host 192.168.57.1 port 22: Connection refused lost connection

36,716

Typically, when this error happens, it means that the SSH client can not establish a successful connection to the SSH server because something refused the connection's ability to exist.

Be sure any firewalls on your computers allow communication both in and out on port 22. If you're using ufw, this command is simply ufw allow 22.

Furthermore, it may be possible that your SSH server is not running. Try to run this command on the server:

sudo service ssh restart

Be sure to pay attention to any errors or the like that are returned (if any).

Also, check your SSH config at /etc/ssh/sshd_config to make sure that the server is actually listening on port 22 and is bound to allow connections. If these are not the case, change the settings appropriately and save the edited file. Restart the SSH server with the command given above.

Share:
36,716

Related videos on Youtube

Apul Gupta
Author by

Apul Gupta

Updated on September 18, 2022

Comments

  • Apul Gupta
    Apul Gupta over 1 year

    I have two linux server running one having static IP(192.168.56.1) other with a static IP(192.168.57.1). I am able to ping both the servers with there static IP but when I tried to move a txt file from one machine to other

    scp /home/sample.txt [email protected]:/home
    

    I got an error ssh: connect to host 192.168.57.1 port 22: Connection refused lost connectionI tried all the things like

    sudo apt-get purge ssh-server
    sudo apt-get install ssh-server ssh-client
    

    and iptables but the problem still persist

    Output after running ssh 192.168.56.1 -vvv:

    output after running ssh 192.168.56.1 -vvv

    • pa4080
      pa4080 over 7 years
      Is the ssh port (22) open into the firewall? Through Iptables: sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT; or through UFW: sudo ufw allow ssh or sudo ufw limit ssh.
    • pa4080
      pa4080 over 7 years
      Please edit your question and paste the output of: ssh 192.168.56.1 -vvv (Verbose mode.). I think, it will be helpful.
  • Apul Gupta
    Apul Gupta over 7 years
    I did both the things i.e ufw allow 22 and the sshd_config file shows the port 22 as the listening port still the problem persists