22

Although This has been discussed, but still i am not able to solve this. Here is a quick review of what i did and how i got into the trouble:

Installed Ubuntu 12.10, installed ssh, sudo apt-get install ssh. The favorite ssh was working fine and connected by using ssh localhost. I removed Ubuntu, increased the partition and again installed Ubuntu. Again I fired sudo apt-get install ssh, it showed me

Reading package lists... Done    
Building dependency tree        
Reading state information... Done

When I given command , ssh localhost, it gave me error as:

ssh: connect to host localhost port 22: Connection refused
4
  • 15
    Can you retry after doing sudo apt-get install openssh-server? – jobin Jan 11 '14 at 15:02
  • What is the output of sudo iptables -L? And sudo netstat -l? – Braiam Apr 23 '14 at 23:41
  • 5
    Installing openssh-server resolved problem – S.M.Mousavi Jan 19 '15 at 9:08
  • Thank you, @Mousavi. That was all I needed. Funny this is not the accepted answer. – SDsolar May 29 '17 at 21:14
17

Fire this command:

sudo iptables -L

If you see that no traffic is allowed (i.e. no specific rules), then run the following command:

sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT

this command tells the system to allow incoming connections to port 22...and usually should solve your dilemma, specifically for ssh / sshd.

UPDATED as of July 31,2016: iptables have nothing to do with ssh as an application, but on other hand, functions as router in allow the traffic to port 22. When using iptables, the system actually understand 'ssh' however, it's a shortcut within command line but, really, it's actually iptables INPUT -p udp -dport 22 while --dport means "destination port" (ssh uses port 22). This probably caused some misconception on seeing 'ssh' as if it's an appication, but really '22' as port.

16
  • There are many sections coming such as Chain ufw-reject-forward, Chain ufw-reject-input, Chain ufw-reject-output... So which section need to refer to check? – user234202 Jan 11 '14 at 14:49
  • Sounds like your traffic is being capped, then go ahead and add that command line and reboot. – Faron Jan 11 '14 at 15:00
  • 2
    I did the same and rebooted , same issue :( – user234202 Jan 11 '14 at 15:12
  • 7
    How exactly did the issue get solved? – Braiam Apr 23 '14 at 23:39
  • 1
    @Kizito iptables have nothing to do with ssh as an application, but on other hand, functions as router in allow the traffic to port 22. When using iptables, the system actually understand 'ssh' however, it's a shortcut within command line but, really, it's actually iptables INPUT -p udp -dport 22 while --dport means "destination port" (ssh uses port 22). This probably caused some misconception on seeing 'ssh' as if it's an appication, but really '22' as port. – Faron Jul 31 '16 at 5:23

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