0

I have a linux server running Ubuntu 16.04. I installed the ssh-server on it and have it running with the sudo ssh service start and can see it with ps aux | grep ssh. I want to ssh into it from my laptop (also running Ubuntu 16.04). They are both connected to the same Wifi. When I ssh from my laptop to the server using ssh username@serverIP, I get

ssh: connect to host <serverIP> port 22: Connection timed out

Since some of the recommendations here was to use another port number and not 22, I changed the port to 2220 in the /etc/ssh/sshd_config file on the server. I then ssh from my laptop using ssh username@serverIP -p 2220 and I get the same connection refused error.

Next I went and manually changed the IP address and netmask of one of the interfaces on the server using ifconfig eth0 <laptopIP + 1> netmask <laptop_subnet> so that it falls under the same subnet as my laptop is. I then tried to ssh using ssh ssh username@LaptopIP+1 -p 2220 and I get

ssh: connect to host <laptopIp+1> port 2220: Connection refused

Am I over complicating this? How do I get a connection to this server?

1
  • 2
    "Connection timed out" "I get the same connection refused error" Connection timed out and Connection refused are different errors with different causes. You should be clear and specific about which error you're getting at different times.
    – Kenster
    Feb 6, 2019 at 19:47

2 Answers 2

0

This is very likely the firewall blocking the connection. You should have a look to see what your firewall policies are with the sudo ufw status command. You may get output that looks similar to this(but likely fewer ports open):

Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere                  
22 (v6)                    ALLOW       Anywhere (v6)             

25,53,80,110,443/tcp       ALLOW OUT   Anywhere                  
53,67,68/udp               ALLOW OUT   Anywhere                  
51413/tcp                  ALLOW OUT   Anywhere                  
51413/udp                  ALLOW OUT   Anywhere                  
6969/tcp                   ALLOW OUT   Anywhere                  
25,53,80,110,443/tcp (v6)  ALLOW OUT   Anywhere (v6)             
53,67,68/udp (v6)          ALLOW OUT   Anywhere (v6)             
51413/tcp (v6)             ALLOW OUT   Anywhere (v6)             
51413/udp (v6)             ALLOW OUT   Anywhere (v6)             
6969/tcp (v6)              ALLOW OUT   Anywhere (v6) 

This will especially be true if you change your port to something other than the default 22. You can allow connections on a specific port by using that same command:

sudo ufw allow 22

or if you want to stick with the alternative port, modify the above command to allow 2220(changing the default port is of course recommended if this is a production or "public" server). Once you've allowed the port, check the status of ufw again to be sure, then try connecting remotely via ssh.

See also: https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands

0

Check the server firewall, you might need to create rules to allow connections to specific ports.

Here is one reference: https://askubuntu.com/questions/9206/is-there-a-preinstalled-or-automatic-firewall

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .