60

I am trying to connect to remote server via ssh but getting connection timeout.

I ran the following command

ssh testkamer@test.dommainname.com

and getting following result

ssh: connect to host testkamer@test.dommainname.com port 22: Connection timed out

but if try to connect on another remote server then I can login successfully.

So I think there is no problem in ssh and other person try to login with same login and password he can successfully login to server.

Please help me
Thanks.

Manish Shrivastava
  • 30,617
  • 13
  • 97
  • 101
urjit on rails
  • 1,763
  • 4
  • 19
  • 36
  • 22
    For whoever comes to this question: this error can have many reasons. To get a more specific response, call the ssh command with the `-vvv` option. E.g. `ssh -vvv testkamer@test.kameronderdehamer.nl`. – brandizzi May 05 '17 at 22:06
  • 1
    I was able to connect using filezilla sftp but when trying to connect from terminal this error started to appear on mac catalina... trying with sudo worked... e.g sudo ssh -i key.pem user@ec2.instance.com – Ahmad Jan 05 '22 at 08:57
  • 6
    In my case i was unable to connect because someone had turned on the firewall (ufw) on the instance and had forgotten to allow ssh ports via `sudo ufw allow ssh`. – oomer Jan 13 '22 at 12:27

27 Answers27

20

Here are a couple of things that could be preventing you from connecting to your Linode instance:

  1. DNS problem: if the computer that you're using to connect to your remote server isn't resolving test.kameronderdehamer.nl properly then you won't be able to reach your host. Try to connect using the public IP address assigned to your Linode and see if it works (e.g. ssh user@123.123.123.123). If you can connect using the public IP but not using the hostname that would confirm that you're having some problem with domain name resolution.

  2. Network issues: there might be some network issues preventing you from establishing a connection to your server. For example, there may be a misconfigured router in the path between you and your host, or you may be experiencing packet loss. While this is not frequent, it has happenned to me several times with Linode and can be very annoying. It could be a good idea to check this just in case. You can have a look at Diagnosing network issues with MTR (from the Linode library).

mfriedman
  • 882
  • 1
  • 9
  • 13
  • 2
    Thank you! I have been troubleshooting how to connect from Windows 10 to my Ubuntu 20.04.2 server for 3 days on and off, trying reinstalling OpenSSH, trying the default port, checking firewalls, checking IP addresses, editing config files, trying different user accounts, everything... turns out that I just needed to reboot my internet router. Oh my God, so simple. FYI for future people, the SSH errors I was got when trying to connect were "resource temporarily unavailable" on WSL and "connection timed out" on the Windows command prompt. – Tania Mar 10 '21 at 19:39
15

That error message means the server to which you are connecting does not reply to SSH connection attempts on port 22. There are three possible reasons for that:

  1. You're not running an SSH server on the machine. You'll need to install it to be able to ssh to it.

  2. You are running an SSH server on that machine, but on a different port. You need to figure out on which port it is running; say it's on port 1234, you then run ssh -p 1234 hostname.

  3. You are running an SSH server on that machine, and it does use the port on which you are trying to connect, but the machine has a firewall that does not allow you to connect to it. You'll need to figure out how to change the firewall, or maybe you need to ssh from a different host to be allowed in.

EDIT: as (correctly) pointed out in the comments, the third is certainly the case; the other two would result in the server sending a TCP "reset" package back upon the client's connection attempt, resulting in a "connection refused" error message, rather than the timeout you're getting. The other two might also be the case, but you need to fix the third first before you can move on.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Akash S
  • 186
  • 1
  • 4
  • I also had a case, when Linux suggested to download last updates. I could not connect until I closed the popped-up window. – fflores Oct 11 '22 at 11:27
6

I got this error and found that I don't have my SSH port (non standard number) whitelisted in config server firewall.

Victor2748
  • 4,149
  • 13
  • 52
  • 89
16851556
  • 255
  • 3
  • 11
5

Just adding this here because it worked for me. Without changing any settings (to my knowledge), I was no longer able to access my AWS EC2 instance with: ssh -i /path/to/key/key_name.pem admin@ecx-x-x-xxx-xx.eu-west-2.compute.amazonaws.com

It turned out I needed to add a rule for inbound SSH traffic, as explained here by AWS. For Port range 22, I added 0.0.0.0/0, which allows all IPv4 addresses to access the instance using SSH.

Note that making the instance accessible to all IPv4 addresses is a security risk; it is acceptable for a short time in a test environment, but you'll likely need a longer term solution.

arranjdavis
  • 657
  • 8
  • 16
4

This happens because of firewall connection. Reset your firewall connection from your hosting website.

It will start working.

After connecting to the server again add this to your (ufw) security

sudo ufw allow 22/tcp
Furqan
  • 81
  • 6
3

If you are on Public Network, Firewall will block all incoming connections by default. check your firewall settings or use private network to SSL

2

The possibility could be, the SSH might not be enabled on your server/system.

  1. Check sudo systemctl status ssh is Active or not.
  2. If it's not active, try installing with the help of these commands

sudo apt update

sudo apt install openssh-server

Now try to access the server/system with following command

ssh username@ip_address

Gani
  • 422
  • 1
  • 8
  • 16
1

There can be many possible reasons for this failure.

Some are listed above. I faced the same issue, it is very hard to find the root cause of the failure.

I will recommend you to check the session timeout for shh from ssh_config file. Try to increase the session timeout and see if it fails again

1

My VPN connection was not enabled. I was trying all possible way to open up the Firwall and Ports until I realized, I am working from home and my VPN connection was down. But yes, Firewall and ssh configurations can be a reason.

sg28
  • 1,363
  • 9
  • 19
1

Try connecting to a vpn, if possible. That was the reason I was facing problem. Tip: if you're using an ec2 machine, try rebooting it. This worked for me the other day :)

dhruv arora
  • 156
  • 1
  • 3
1

I had this issue while trying to ssh into a local nextcloud server from my Mac.

I had no issues ssh-ing in once, but if I tried to have more than one concurrent connection, it would hang until it timed out.

Note, I was sshing to my user@public-ip-address.

I realized the second connection only didn't work when I tried to ssh into it when on the same network, ie my home network

Furthermore, when I tried ssh user@server-domain it worked!

The end fix was to use ssh user@server-domain rather than ssh user@public-ip

Jacob Waters
  • 307
  • 1
  • 3
  • 11
1

This may be very case specific and work in some cases only but check to see if you were previously connecting through some VPN software/application.

Try connecting again to the VPN. Worked in my case.

Abhinav Dobhal
  • 598
  • 7
  • 12
1

I have experienced a couple of nasty issues that lead to these errors, and these are different from everyone else's answer here:

  1. Wrong folder access rights. You need to have specific directory permissions on you ssh folders and files. a. The .ssh directory permissions should be 700 (drwx------).

    b. The public key (.pub file) should be 644 (-rw-r--r--).

    c. The private key (id_rsa) on the client host, and the authorized_keys file on the server, should be 600 (-rw-------).

  2. Nasty docker network configuration. This just happened to me on an AWS EC2 instance. It turned out that I had a docker network with an ip range that interfered with the ssh access granted by the security group and VPC. The docker network's range was e.g. 192.168.176.0/20 (i.e. a range from 192.168.176.1->192.168.191.254), whereas the security group had a range of 192.168.179.0/24; interfering with the SSH access.

Andreas Forslöw
  • 2,220
  • 23
  • 32
0

I had this error when trying to SSH into my Raspberry pi from my MBP via bash terminal. My RPI was connected to the network via wifi/wlan0 and this IP had been changed upon restart by my routers DHCP.

Check IP being used to login via SSH is correct. Re-check IP of device being SSH'd into (in my case the RPI), which can be checked using hostname -I

Confirm/amend SSH login credentials on "guest" device (in my case the MBP) and it worked fine in my attempt.

0

I faced a similar issue. I checked for the below:

  1. if ssh is not installed on your machine, you will have to install it firstly. (You will get a message saying ssh is not recognized as a command).
  2. Port 22 is open or not on the server you are trying to ssh.
  3. If the control of remote server is in your hands and you have permissions, try to disable firewall on it.
  4. Try to ssh again.

If port is not an issue then you would have to check for firewall settings as it is the one that is blocking your connection.

For me too it was a firewall issue between my machine and remote server.I disabled the firewall on the remote server and I was able to make a connection using ssh.

Atul Patel
  • 543
  • 4
  • 11
0

my main machine is windows 10 and I have CEntOS 7 VBox
Search in your main machine for "known_hosts"
usually, known_host location in windows in "user/.ssh/known_host"
open it using notepad and delete the line where your centos vbox ip
then try connect in your terminal

in mac os user you can find known_hosts in "~/.ssh/known_hosts"

0

Make sure to ask the admin to authorize your device.

On Linux run: sudo zerotier-cli listnetworks

if it returns status ACCESS DENIED ask the admin to authorize your node. This is mentioned here. https://discuss.zerotier.com/t/solved-cant-join-network/1919

Noman Tanveer
  • 175
  • 1
  • 2
  • 9
0

This issue is also caused if the Dynamic Host Configuration Protocol is not set-up properly.

To solve this first check if your IP Address is configured using ping ipaddress, If there is no packet loss and the IP Address is working fine try any other solution. If there is no response and you have 100% packet loss, it means that your IP Address is not working and not configured.

Now configure your IP Address using,

sudo dhclient -v devicename

To check your device you can use the 'ip a' command For eg. My device was usb0 since I had connected the device through usb

This will configure an IP Address automatically and you can even see which one is configured. You can again check with the 'ip a' command to confirm.

Dharman
  • 30,962
  • 25
  • 85
  • 135
RISHI
  • 1
  • 3
0

This happened to me after enabling port 22 with "sudo ufw allow ssh". Before that, I was getting a refusal from my machine when entering with ssh from another one. After enabling it, I thought it would work, but instead it showed the message "connection timed out". As I had just installed Ubuntu with the option of installing basic functions alongside, I checked whether I had the openssh-server with the command sudo apt list --installed | grep openssh-server. It turned out that Ubuntu had installed by defect the openssh-client instead. I uninstalled it and installed the openssh-server following the basic commands:

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

After that, a simple "sudo ufw allow ssh" worked perfectly and I was finally able to access the machine with an ssh command.

0

What worked for me was that i went to my security group and reset my IP and it worked

Forbes
  • 1
  • 2
0

Here are some considerations which i took to resolve a similar issue that I had:

  • Port 22
  • IGW (Internet Gateway)
  • VPC

Scene 1> This is for port 22 not enabled with right configurations. If the port is set to custom or myip, the probable scene is this won't work.

Scene 2> When you delete the internet gateway, the network is created and the instance will be functional too, but the routing from the internet will not work. Hence make sure that if there is a VPC, it has an Internet Gateway attached.

Scene 3> Check the VPC for the subnet associations and routing table entries. This might probably tell you the cause. I found one in this kind of troubleshooting. The route used to land up in a "blackhole" (shows up in the route table section of the console). To fix this I had to check and find out my internet gateway and found the issue with the IGW.

Moral of the story: always trace backward in the network!

Sachin
  • 1
  • 2
0

In my case I'm on windows, I reset my firewall settings, and it fixed

Shahjahan
  • 171
  • 2
  • 3
0
  1. If you get any error check the basic a version control request with ssh -V and If it is not installed, install it with the sudo apt-get install openssh-server command.

  2. Check your virtual machine ssh connection with sudo service ssh status at console.

  3. Check "Active" rows and if write a inactive(dead) the console write sudo service ssh start

Result: Now you can check your connection with sudo service ssh status command and send ssh connection request.

Adem
  • 41
  • 1
  • 4
0

Reset the firewall and reboot your VPS from your hosting service, it will start working perfectly fine

Furqan
  • 81
  • 6
-1

check whether accidentally you have deleted the default vpc or default subnets ,while creating your own vpc and subnets. I have done this mistake while creating vpc, hence got this error while connecting via ssh.

alos check whether u have attched IGW to public subnets.

-1

Its not complicated. First, go disable your firewall(USE YOUR CONTROL PANEL)after you check if your openssh is active.

Disable firewall, then use putty or any alternative to basically disable using this command sudo ufw disable

try now

  • 2
    Starting your answer with "its not complicated" adds nothing of content to your post but does demean the asker of the question and go against the welcoming nature of the community. The overall content of your answer is "Have you tried disabling your firewall." Though this is a good troubleshooting step, it is not worthy of a full answer and would have been better left as a comment. When writing answers in the future please refrain from being demeaning to the person who asked the question/. – jjr2000 Dec 21 '22 at 10:56
-4

Update the security group of that instance. Your local IP must have updated. Every time it’s IP flips. You will have to go update the Security group.