ssh connection refused











up vote
3
down vote

favorite
2












Hi I'm having a problem with my ssh, which is magically stopped working and I couldn't figure out why. The message it give is:



ssh: connect to host <host> port 22: Connection refused


I don't see any error messages when I write dmesg but I'm getting following from telnet localhost 22



Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused


I tried the solutions that I saw in some similar cases [1] and [2] but it still didn't solve my problem the entries and outputs are as follows:



>> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
>> sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Note that this was already ACCEPT I didn't had any problem even before entering the command sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT. I also tried to reboot ssh but it didn't change anything



>>netstat -a | egrep 'Proto|LISTEN'
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:20128 *:* LISTEN
tcp 0 0 localhost:17600 *:* LISTEN
tcp 0 0 localhost:20129 *:* LISTEN
tcp 0 0 localhost:17603 *:* LISTEN
tcp 0 0 localhost:21128 *:* LISTEN
tcp 0 0 deathstar:domain *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 *:db-lsp *:* LISTEN
tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN
tcp6 0 0 [::]:db-lsp [::]:* LISTEN


I don't know what else to try so hope this is enough to solve the problem.



Rest is added after @Ashu's comment



sudo lsof -i | grep ssh


nothing happened



>>netstat -l --numeric-ports | grep 22
unix 2 [ ACC ] STREAM LISTENING 1618183 @jack-com.canonical.Unity.Master.Scope.files.T1731348652205882

>>sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Eddited after @TheSchwa's comment



>>ps aux | grep sshd
jack 3711 0.0 0.0 15944 2220 pts/26 S+ 14:08 0:00 grep --color=auto sshd









share|improve this question
























  • can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
    – Ashu
    Feb 26 '16 at 0:02






  • 1




    On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
    – TheSchwa
    Feb 26 '16 at 1:52










  • @Ashu I added them in the question.
    – jackaraz
    Feb 26 '16 at 15:27












  • @TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
    – jackaraz
    Feb 26 '16 at 15:28










  • Check if sshd is running on the remote machine with ps aux | grep sshd.
    – TheSchwa
    Feb 26 '16 at 17:12















up vote
3
down vote

favorite
2












Hi I'm having a problem with my ssh, which is magically stopped working and I couldn't figure out why. The message it give is:



ssh: connect to host <host> port 22: Connection refused


I don't see any error messages when I write dmesg but I'm getting following from telnet localhost 22



Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused


I tried the solutions that I saw in some similar cases [1] and [2] but it still didn't solve my problem the entries and outputs are as follows:



>> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
>> sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Note that this was already ACCEPT I didn't had any problem even before entering the command sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT. I also tried to reboot ssh but it didn't change anything



>>netstat -a | egrep 'Proto|LISTEN'
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:20128 *:* LISTEN
tcp 0 0 localhost:17600 *:* LISTEN
tcp 0 0 localhost:20129 *:* LISTEN
tcp 0 0 localhost:17603 *:* LISTEN
tcp 0 0 localhost:21128 *:* LISTEN
tcp 0 0 deathstar:domain *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 *:db-lsp *:* LISTEN
tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN
tcp6 0 0 [::]:db-lsp [::]:* LISTEN


I don't know what else to try so hope this is enough to solve the problem.



Rest is added after @Ashu's comment



sudo lsof -i | grep ssh


nothing happened



>>netstat -l --numeric-ports | grep 22
unix 2 [ ACC ] STREAM LISTENING 1618183 @jack-com.canonical.Unity.Master.Scope.files.T1731348652205882

>>sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Eddited after @TheSchwa's comment



>>ps aux | grep sshd
jack 3711 0.0 0.0 15944 2220 pts/26 S+ 14:08 0:00 grep --color=auto sshd









share|improve this question
























  • can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
    – Ashu
    Feb 26 '16 at 0:02






  • 1




    On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
    – TheSchwa
    Feb 26 '16 at 1:52










  • @Ashu I added them in the question.
    – jackaraz
    Feb 26 '16 at 15:27












  • @TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
    – jackaraz
    Feb 26 '16 at 15:28










  • Check if sshd is running on the remote machine with ps aux | grep sshd.
    – TheSchwa
    Feb 26 '16 at 17:12













up vote
3
down vote

favorite
2









up vote
3
down vote

favorite
2






2





Hi I'm having a problem with my ssh, which is magically stopped working and I couldn't figure out why. The message it give is:



ssh: connect to host <host> port 22: Connection refused


I don't see any error messages when I write dmesg but I'm getting following from telnet localhost 22



Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused


I tried the solutions that I saw in some similar cases [1] and [2] but it still didn't solve my problem the entries and outputs are as follows:



>> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
>> sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Note that this was already ACCEPT I didn't had any problem even before entering the command sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT. I also tried to reboot ssh but it didn't change anything



>>netstat -a | egrep 'Proto|LISTEN'
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:20128 *:* LISTEN
tcp 0 0 localhost:17600 *:* LISTEN
tcp 0 0 localhost:20129 *:* LISTEN
tcp 0 0 localhost:17603 *:* LISTEN
tcp 0 0 localhost:21128 *:* LISTEN
tcp 0 0 deathstar:domain *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 *:db-lsp *:* LISTEN
tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN
tcp6 0 0 [::]:db-lsp [::]:* LISTEN


I don't know what else to try so hope this is enough to solve the problem.



Rest is added after @Ashu's comment



sudo lsof -i | grep ssh


nothing happened



>>netstat -l --numeric-ports | grep 22
unix 2 [ ACC ] STREAM LISTENING 1618183 @jack-com.canonical.Unity.Master.Scope.files.T1731348652205882

>>sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Eddited after @TheSchwa's comment



>>ps aux | grep sshd
jack 3711 0.0 0.0 15944 2220 pts/26 S+ 14:08 0:00 grep --color=auto sshd









share|improve this question















Hi I'm having a problem with my ssh, which is magically stopped working and I couldn't figure out why. The message it give is:



ssh: connect to host <host> port 22: Connection refused


I don't see any error messages when I write dmesg but I'm getting following from telnet localhost 22



Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused


I tried the solutions that I saw in some similar cases [1] and [2] but it still didn't solve my problem the entries and outputs are as follows:



>> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
>> sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Note that this was already ACCEPT I didn't had any problem even before entering the command sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT. I also tried to reboot ssh but it didn't change anything



>>netstat -a | egrep 'Proto|LISTEN'
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:20128 *:* LISTEN
tcp 0 0 localhost:17600 *:* LISTEN
tcp 0 0 localhost:20129 *:* LISTEN
tcp 0 0 localhost:17603 *:* LISTEN
tcp 0 0 localhost:21128 *:* LISTEN
tcp 0 0 deathstar:domain *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 *:db-lsp *:* LISTEN
tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN
tcp6 0 0 [::]:db-lsp [::]:* LISTEN


I don't know what else to try so hope this is enough to solve the problem.



Rest is added after @Ashu's comment



sudo lsof -i | grep ssh


nothing happened



>>netstat -l --numeric-ports | grep 22
unix 2 [ ACC ] STREAM LISTENING 1618183 @jack-com.canonical.Unity.Master.Scope.files.T1731348652205882

>>sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Eddited after @TheSchwa's comment



>>ps aux | grep sshd
jack 3711 0.0 0.0 15944 2220 pts/26 S+ 14:08 0:00 grep --color=auto sshd






networking server ssh firewall






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:39









Community

1




1










asked Feb 25 '16 at 23:39









jackaraz

165119




165119












  • can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
    – Ashu
    Feb 26 '16 at 0:02






  • 1




    On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
    – TheSchwa
    Feb 26 '16 at 1:52










  • @Ashu I added them in the question.
    – jackaraz
    Feb 26 '16 at 15:27












  • @TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
    – jackaraz
    Feb 26 '16 at 15:28










  • Check if sshd is running on the remote machine with ps aux | grep sshd.
    – TheSchwa
    Feb 26 '16 at 17:12


















  • can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
    – Ashu
    Feb 26 '16 at 0:02






  • 1




    On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
    – TheSchwa
    Feb 26 '16 at 1:52










  • @Ashu I added them in the question.
    – jackaraz
    Feb 26 '16 at 15:27












  • @TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
    – jackaraz
    Feb 26 '16 at 15:28










  • Check if sshd is running on the remote machine with ps aux | grep sshd.
    – TheSchwa
    Feb 26 '16 at 17:12
















can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
– Ashu
Feb 26 '16 at 0:02




can you try these commands 'sudo lsof -i | grep ssh', 'netstat -l --numeric-ports | grep 22', 'sudo iptables --list'
– Ashu
Feb 26 '16 at 0:02




1




1




On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
– TheSchwa
Feb 26 '16 at 1:52




On what machine are you running telnet localhost 22? Do you have any way to access the remote machine other than ssh?
– TheSchwa
Feb 26 '16 at 1:52












@Ashu I added them in the question.
– jackaraz
Feb 26 '16 at 15:27






@Ashu I added them in the question.
– jackaraz
Feb 26 '16 at 15:27














@TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
– jackaraz
Feb 26 '16 at 15:28




@TheSchwa I can physically access to the machine if you are asking that and all those commands above ran in the machine that I'm trying to ssh in to.
– jackaraz
Feb 26 '16 at 15:28












Check if sshd is running on the remote machine with ps aux | grep sshd.
– TheSchwa
Feb 26 '16 at 17:12




Check if sshd is running on the remote machine with ps aux | grep sshd.
– TheSchwa
Feb 26 '16 at 17:12










6 Answers
6






active

oldest

votes

















up vote
12
down vote



accepted










I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:



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


so now its working.






share|improve this answer





















  • unexpected, but did work :
    – bhelm
    Jul 16 at 9:08


















up vote
4
down vote













TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.



First of all double check your host name and/or IP address.



The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.



If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:



tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd



If you don't try starting sshd and/or checking whether it is configured to listen on port 22.



EDIT



The bits to focus on are:



:22 - port 22



LISTEN - there is a process running and expecting incoming connections on port 22



sshd - the name of the process.



If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.






share|improve this answer























  • I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
    – jackaraz
    Feb 26 '16 at 19:17


















up vote
2
down vote













Your server firewall is configured to have the port open, but nothing is listening to respond to your connection.



You need to have sshd (the ssh daemon)installed, and running...



https://help.ubuntu.com/community/SSH/OpenSSH/Configuring






share|improve this answer





















  • It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
    – hazrpg
    Feb 27 '16 at 13:50










  • @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
    – fiprojects
    Feb 27 '16 at 15:57










  • True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
    – hazrpg
    Feb 27 '16 at 16:19




















up vote
2
down vote













SSH Connection refused because of the following reason-




  1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.


  2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.


  3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.



*Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.






share|improve this answer




























    up vote
    1
    down vote













    One of the most common issue causing this is the sshd services itself. Did you check if it is actually running? Also, I noticed you are directly editing your iptables, so if you had ufw/firewalld running -- might as well check it.



    Also make sure that the ssh server is running the right IP and the FQDN is routing to the right IP Address.






    share|improve this answer




























      up vote
      0
      down vote













      You have to create missing directory like this



      mkdir /var/run/sshd
      chmod 0755 /var/run/sshd


      Then start faulty shh server up with:



      service ssh start


      And that's it!






      share|improve this answer








      New contributor




      krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.


















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f739164%2fssh-connection-refused%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        12
        down vote



        accepted










        I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:



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


        so now its working.






        share|improve this answer





















        • unexpected, but did work :
          – bhelm
          Jul 16 at 9:08















        up vote
        12
        down vote



        accepted










        I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:



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


        so now its working.






        share|improve this answer





















        • unexpected, but did work :
          – bhelm
          Jul 16 at 9:08













        up vote
        12
        down vote



        accepted







        up vote
        12
        down vote



        accepted






        I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:



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


        so now its working.






        share|improve this answer












        I first tried to remove and reinstall ssh but it didn't work for me then I tried to purge it:



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


        so now its working.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 26 '16 at 22:04









        jackaraz

        165119




        165119












        • unexpected, but did work :
          – bhelm
          Jul 16 at 9:08


















        • unexpected, but did work :
          – bhelm
          Jul 16 at 9:08
















        unexpected, but did work :
        – bhelm
        Jul 16 at 9:08




        unexpected, but did work :
        – bhelm
        Jul 16 at 9:08












        up vote
        4
        down vote













        TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.



        First of all double check your host name and/or IP address.



        The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.



        If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:



        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd



        If you don't try starting sshd and/or checking whether it is configured to listen on port 22.



        EDIT



        The bits to focus on are:



        :22 - port 22



        LISTEN - there is a process running and expecting incoming connections on port 22



        sshd - the name of the process.



        If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.






        share|improve this answer























        • I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
          – jackaraz
          Feb 26 '16 at 19:17















        up vote
        4
        down vote













        TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.



        First of all double check your host name and/or IP address.



        The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.



        If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:



        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd



        If you don't try starting sshd and/or checking whether it is configured to listen on port 22.



        EDIT



        The bits to focus on are:



        :22 - port 22



        LISTEN - there is a process running and expecting incoming connections on port 22



        sshd - the name of the process.



        If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.






        share|improve this answer























        • I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
          – jackaraz
          Feb 26 '16 at 19:17













        up vote
        4
        down vote










        up vote
        4
        down vote









        TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.



        First of all double check your host name and/or IP address.



        The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.



        If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:



        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd



        If you don't try starting sshd and/or checking whether it is configured to listen on port 22.



        EDIT



        The bits to focus on are:



        :22 - port 22



        LISTEN - there is a process running and expecting incoming connections on port 22



        sshd - the name of the process.



        If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.






        share|improve this answer














        TCP error "Connection refused" means that there is a host active on this IP address but the port you were trying to connect to (22 for ssh) is not open.



        First of all double check your host name and/or IP address.



        The most likely reason is either somebody stopped the ssh daemon or somebody configured it to use an alternative port instead of the default 22.



        If you have physical access to your server logon to that server and type in command sudo netstat -tupan. Ideally you should see a line like:



        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1053/sshd



        If you don't try starting sshd and/or checking whether it is configured to listen on port 22.



        EDIT



        The bits to focus on are:



        :22 - port 22



        LISTEN - there is a process running and expecting incoming connections on port 22



        sshd - the name of the process.



        If you can't see a line like that then perhaps your ssh server is badly configured and fails to start. Try this page for instructions how to run it in the foreground and troubleshoot it.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 27 '16 at 10:56

























        answered Feb 26 '16 at 0:04









        sмurf

        4,05611526




        4,05611526












        • I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
          – jackaraz
          Feb 26 '16 at 19:17


















        • I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
          – jackaraz
          Feb 26 '16 at 19:17
















        I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
        – jackaraz
        Feb 26 '16 at 19:17




        I had so many similar lines ending with CLOSE_WAIT LISTEN ESTABLISHED etc. but I dont know the meaning of all those lines
        – jackaraz
        Feb 26 '16 at 19:17










        up vote
        2
        down vote













        Your server firewall is configured to have the port open, but nothing is listening to respond to your connection.



        You need to have sshd (the ssh daemon)installed, and running...



        https://help.ubuntu.com/community/SSH/OpenSSH/Configuring






        share|improve this answer





















        • It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
          – hazrpg
          Feb 27 '16 at 13:50










        • @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
          – fiprojects
          Feb 27 '16 at 15:57










        • True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
          – hazrpg
          Feb 27 '16 at 16:19

















        up vote
        2
        down vote













        Your server firewall is configured to have the port open, but nothing is listening to respond to your connection.



        You need to have sshd (the ssh daemon)installed, and running...



        https://help.ubuntu.com/community/SSH/OpenSSH/Configuring






        share|improve this answer





















        • It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
          – hazrpg
          Feb 27 '16 at 13:50










        • @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
          – fiprojects
          Feb 27 '16 at 15:57










        • True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
          – hazrpg
          Feb 27 '16 at 16:19















        up vote
        2
        down vote










        up vote
        2
        down vote









        Your server firewall is configured to have the port open, but nothing is listening to respond to your connection.



        You need to have sshd (the ssh daemon)installed, and running...



        https://help.ubuntu.com/community/SSH/OpenSSH/Configuring






        share|improve this answer












        Your server firewall is configured to have the port open, but nothing is listening to respond to your connection.



        You need to have sshd (the ssh daemon)installed, and running...



        https://help.ubuntu.com/community/SSH/OpenSSH/Configuring







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 26 '16 at 19:27









        fiprojects

        1212




        1212












        • It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
          – hazrpg
          Feb 27 '16 at 13:50










        • @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
          – fiprojects
          Feb 27 '16 at 15:57










        • True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
          – hazrpg
          Feb 27 '16 at 16:19




















        • It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
          – hazrpg
          Feb 27 '16 at 13:50










        • @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
          – fiprojects
          Feb 27 '16 at 15:57










        • True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
          – hazrpg
          Feb 27 '16 at 16:19


















        It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
        – hazrpg
        Feb 27 '16 at 13:50




        It is best to make sure you outline the steps found on the page you linked in your answer, because links may become broken at any time. By all means add a link for reference, however always make sure to include the steps too.
        – hazrpg
        Feb 27 '16 at 13:50












        @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
        – fiprojects
        Feb 27 '16 at 15:57




        @hazrpg I was aware of this rule, but figured if help.ubuntu.com was to go away, then this group would go with it. I accept your comment though and will remember it in future.
        – fiprojects
        Feb 27 '16 at 15:57












        True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
        – hazrpg
        Feb 27 '16 at 16:19






        True, but a wiki page can easily changed by anyone. I have known wiki pages to be moved without the old reference being linked to the new location. However, I appreciate the fact that you already knew about the ruling - just remember that any link/site/page can change or be deleted at any time (regardless of its location).
        – hazrpg
        Feb 27 '16 at 16:19












        up vote
        2
        down vote













        SSH Connection refused because of the following reason-




        1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.


        2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.


        3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.



        *Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.






        share|improve this answer

























          up vote
          2
          down vote













          SSH Connection refused because of the following reason-




          1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.


          2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.


          3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.



          *Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.






          share|improve this answer























            up vote
            2
            down vote










            up vote
            2
            down vote









            SSH Connection refused because of the following reason-




            1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.


            2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.


            3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.



            *Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.






            share|improve this answer












            SSH Connection refused because of the following reason-




            1. default port(22) has been changed to something others. Check your /etc/ssh/sshd_config file for any change in port.


            2. IP conflict on the LAN. Use arping command to determine any conflict. see your dhcp pool.


            3. ssh port is not allowed on ip-tables/firewall. Check your iptables/firewall and allow.



            *Uninstall/Reinstall ssh package is not a good idea because it will change many key and pass.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 15 '16 at 9:32









            Faisal Md. Jiaur Rahman

            211




            211






















                up vote
                1
                down vote













                One of the most common issue causing this is the sshd services itself. Did you check if it is actually running? Also, I noticed you are directly editing your iptables, so if you had ufw/firewalld running -- might as well check it.



                Also make sure that the ssh server is running the right IP and the FQDN is routing to the right IP Address.






                share|improve this answer

























                  up vote
                  1
                  down vote













                  One of the most common issue causing this is the sshd services itself. Did you check if it is actually running? Also, I noticed you are directly editing your iptables, so if you had ufw/firewalld running -- might as well check it.



                  Also make sure that the ssh server is running the right IP and the FQDN is routing to the right IP Address.






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    One of the most common issue causing this is the sshd services itself. Did you check if it is actually running? Also, I noticed you are directly editing your iptables, so if you had ufw/firewalld running -- might as well check it.



                    Also make sure that the ssh server is running the right IP and the FQDN is routing to the right IP Address.






                    share|improve this answer












                    One of the most common issue causing this is the sshd services itself. Did you check if it is actually running? Also, I noticed you are directly editing your iptables, so if you had ufw/firewalld running -- might as well check it.



                    Also make sure that the ssh server is running the right IP and the FQDN is routing to the right IP Address.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 26 '16 at 0:07









                    upbeta01

                    885




                    885






















                        up vote
                        0
                        down vote













                        You have to create missing directory like this



                        mkdir /var/run/sshd
                        chmod 0755 /var/run/sshd


                        Then start faulty shh server up with:



                        service ssh start


                        And that's it!






                        share|improve this answer








                        New contributor




                        krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          up vote
                          0
                          down vote













                          You have to create missing directory like this



                          mkdir /var/run/sshd
                          chmod 0755 /var/run/sshd


                          Then start faulty shh server up with:



                          service ssh start


                          And that's it!






                          share|improve this answer








                          New contributor




                          krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You have to create missing directory like this



                            mkdir /var/run/sshd
                            chmod 0755 /var/run/sshd


                            Then start faulty shh server up with:



                            service ssh start


                            And that's it!






                            share|improve this answer








                            New contributor




                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            You have to create missing directory like this



                            mkdir /var/run/sshd
                            chmod 0755 /var/run/sshd


                            Then start faulty shh server up with:



                            service ssh start


                            And that's it!







                            share|improve this answer








                            New contributor




                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered Nov 20 at 14:07









                            krysits

                            11




                            11




                            New contributor




                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            krysits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f739164%2fssh-connection-refused%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                How did Captain America manage to do this?

                                迪纳利

                                南乌拉尔铁路局