Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to server via ssh - Resource temporarily unavailable #2278

Closed
WurstCommander opened this issue Jul 2, 2017 · 35 comments
Closed

Comments

@WurstCommander
Copy link

WurstCommander commented Jul 2, 2017

This a reopening / copy from "Can't connect to server via ssh #809" - #809 (comment)

If you watch the last comments you can see that the problem isn't fixed:

same here:

ssh -v root@192.168.0.7
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.0.7 [192.168.0.7] port 22.
debug1: connect to address 192.168.0.7 port 22: Resource temporarily unavailable
ssh: connect to host 192.168.0.7 port 22: Resource temporarily unavailable

This is trying to connect to a machine on my home network.

But if i try to ssh to a linux virtual machine running on my PC, it works and it connects without any issues:

ssh -v root@192.168.168.129
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.168.129 [192.168.168.129] port 22.
debug1: Connection established.
debug1: identity file /home/xxx/.ssh/id_rsa type -1
debug1: identity file /home/xxx/.ssh/id_rsa-cert type -1
debug1: identity file /home/xxx/.ssh/id_dsa type -1
debug1: identity file /home/xxx/.ssh/id_dsa-cert type -1
debug1: identity file /home/xxx/.ssh/id_ecdsa type -1
debug1: identity file /home/xxx/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/xxx/.ssh/id_ed25519 type -1
debug1: identity file /home/xxx/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-sha1-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 28:59:dc:aa:da:d5:af:39:7a:82:88:23:b7:11:f9:f7
debug1: Host '192.168.168.129' is known and matches the ECDSA host key.
debug1: Found key in /home/dave/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/xxx/.ssh/id_rsa
debug1: Trying private key: /home/dxxxave/.ssh/id_dsa
debug1: Trying private key: /home/xxx/.ssh/id_ecdsa
debug1: Trying private key: /home/xxx/.ssh/id_ed25519
debug1: Next authentication method: password
rootdebug1: Authentication succeeded (password).
Authenticated to 192.168.168.129 ([192.168.168.129]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = it_IT.UTF-8
debug1: Sending env LC_CTYPE = it_IT.UTF-8
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)

Documentation: https://help.ubuntu.com
Management: https://landscape.canonical.com
Support: https://ubuntu.com/advantage
Last login: Sat Jul 1 10:56:55 2017 from 192.168.168.1

I got the same issue:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to wurstbanane [192.168.1.132] port 22.
debug1: connect to address 192.168.1.132 port 22: Resource temporarily unavailable
ssh: connect to host wurstbanane port 22: Resource temporarily unavailable

There are multiple people in the old issue posting the same problem. I tried git bash, cgywin, bitverise and Filezilla which all connect without a problem. I tried reinstalling BashOnWindows, nothing works.

If you need some logs etc. I could provide them and help.

Thank you.

@MikeGitb
Copy link

MikeGitb commented Jul 6, 2017

Might help if you add your windows version and what firewall / antivirus you use (if any)

@WurstCommander
Copy link
Author

Windows 10 Pro
Version 1703
Built 15063.447

Windows Defender and Windows Firewall, nothing else.

@sunilmut
Copy link
Member

sunilmut commented Jul 6, 2017

@WurstCommander - Thanks for your post. If you can try couple of things and in the order and share your results, that would be great.

  1. Does ssh -v root@192.168.0.7 work from a putty or some other remote SSH application?
  2. If (1) works, can you try "ping 192.168.0.7" from within WSL/bash?
  3. If (2) works as well, can you collect a trace of the failing ssh command and share the trace file? strace -o <trace_file> -ff ssh -v root@192.168.0.7

@WurstCommander
Copy link
Author

WurstCommander commented Jul 12, 2017

Does ssh -v root@192.168.0.7 work from a putty or some other remote SSH application?

yeah it does (IP changed of the server)

ssh -v root@wurstbanane
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017
debug1: Connecting to wurstbanane [192.168.1.190] port 22.
debug1: Connection established.
....

I sadly just deinstalled bash for windows because it didn't work, maybe I'll get me motivated again :-)

@alansill
Copy link

alansill commented Jul 13, 2017

I see the same problem on two different WSL installations - both Windows 10 with all updates and the latest available WSL installed for this Windows version:

Windows 10 Enterprise, Version 1703, OS Build 15063.483

Within bash, "uname -a" yields (replacing the node name here with "localnode")
Linux localnode 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

Also within bash, "lsb_release -a" yields
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

I ran the strace command you requested. Output, edited to replace account and machine name details, is in the file attached. Hope this gives you enough to work on.
strace-ssh.temp.txt

@Leon99
Copy link

Leon99 commented Jul 14, 2017

The same story here. The problem started after I configured my Hassbian for a static IP. Nothing else changed, just rebooted my RPi - worked fine before reboot/reconfiguration, "Resource temporarily unavailable" after.

@WurstCommander
Copy link
Author

@alansill thx for doing "my work". I just hadn't the time to reinstall bash for windows.

@sxhexe
Copy link

sxhexe commented Jul 21, 2017

Adding a windows firewall rule worked for me. Basically you need to tell the firewall to allow the port you use for ssh. Configurations you need to do are similar to this.

@alenmeister
Copy link

@sxhexe Thanks for the insight. Worked for me as well. I added an outbound rule for port 22.

@jshirley338
Copy link

I was having the same problem Win 10 Pro insider preview build 16281. I had SSH working fine for logging into our Esxi Shell, and out of no where it was giving the same error, but like @alenmeister I added rule to firewall for port 22 and that cured my issue. Thanks for the feed back.

@bitcrazed
Copy link
Contributor

All: If you're trying to ssh into an sshd "server" running in WSL, you'll likely hit the "port 22: Resource temporarily unavailable" error if:

  1. Port 22 isn't visible externally because a firewall is blocking access to that port
  2. You've closed the last Console attached to a distro which terminates all running instances of that distro, thus shutting-down sshd
  3. You've logged-off the "server" which terminates all distro instances

@WurstCommander - your first example, where you see this error when trying to access a machine on your network is most likely caused by the firewall on that machine blocking access to port 22. Your second example, of being able to connect to ssdh running on a Linux VM on your local machine is because that Linux instance isn't running a firewall, or the installed firewall exposes port 22 to the public network.

You can list the ports open on your WSL "server" by running netstat -a from PowerShell/Cmd and looking for open port 22
image

I'll write up some instructions and additional info on this scenario on our blog (https://blogs.msdn.microsoft.com/commandline) as it seems to be causing problems.

@FrederikHeber
Copy link

I had the same problem (logging onto a VM running ubuntu) because I had prematurely added an entry in $HOME/.ssh/config allowing IdentitiesOnly as login on my local machine. However, the pub key had not been added to .ssh/authorized_keys, yet.

So, setting IdentitiesOnly to false, then using ssh-copy-id and finally login worked.

@Diluka
Copy link

Diluka commented Dec 26, 2017

use telnet seems there is no firewall problem

Diluka@Diluka-Z7:~/.ssh$ telnet 192.168.250.189 22
Trying 192.168.250.189...
Connected to 192.168.250.189.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2

but ssh can't establish connection

Diluka@Diluka-Z7:~/.ssh$ ssh -v diluka@192.168.250.189
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.250.189 [192.168.250.189] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/Diluka/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.250.189:22 as 'diluka'
debug1: SSH2_MSG_KEXINIT sent
Connection closed by 192.168.250.189 port 22

@bitcrazed
Copy link
Contributor

@Diluka Note that Linux binaries run atop WSL alongside Win32 process, and that both run ABOVE the firewall. This for traffic between Win32 and Linux processes on the same machine do not reach the Windows firewall & should be able to communicate relatively unhindered.

If you're trying to ssh into a "remote" ssh server, you will need to ensure that the firewall in front of your ssh server has exposed the ssh server's port (22 in your example above) to the external network.

Also, if you want to use shared key authentication, you'll need to register your client's SSH public key with your ssh server.

@Diluka
Copy link

Diluka commented Jan 4, 2018

solved it by reinstall openssh-server

@bitcrazed
Copy link
Contributor

@Diluka Thanks for letting us know.

@WurstCommander Could you please close this issue if your problem is resolved?

@naefl
Copy link

naefl commented Jan 17, 2018

Version: windows 10 home build 16299. Had same problem.

I solved it, either because I had accidentally ssh'd with sudo or because reinstalled openssh-server (changed both, can't establish clear causation)

@bitcrazed
Copy link
Contributor

Thanks @naefl.

Hey @WurstCommander - can you confirm if this issue is now resolved, and close this issue if it is?

@ketozhang
Copy link

ketozhang commented Mar 22, 2018

UPDATE - SOLVED:

Xfinity's provided rented modem/router was the issue. Highly recommend you to end that plan and get your own especially if you want a home server.


While I am able to get localhost to work on ports 22 (and others), unfortunately, it doesn't work on when trying to connect through public IP.

$ ssh [user]@localhost -p [port] # works
$ ssh [user]@10.0.0.2 -p [port] # works
$ ssh [user]@[public_ip] -p [port] 
ssh: connect to host [public_ip] port [port]: Resource temporarily unavailable
  • Static ip address set to 10.0.0.2 (otherwise line 2 wouldn't work)
  • Confirmed ports (22 and others) show up as LISTENING on netstat -a
  • Router port forwarded my ports (22 and others) to the correct static address
  • Windows Firewall allows ports 22 and others on Inbound Rules
  • sshd_config set Port to listen to ports 22 and others.
  • Factory reset router and redid all the shenanigans.

I've gotten this to worked perfectly and was able to use my computer as a WAN-accessible server. However I've deleted WSL and redid everything now it doesn't work. Maybe things change in later Windows build?

Windows Build: 17115


Sorry if I'm posting this in the wrong place, very similar issue so I didn't want to make another one. Lmk if I should.

@sunilmut
Copy link
Member

@ketozhang - Not sure I fully understand your setup. Are you trying to SSH into WSL or SSH'ing from WSL or both? If you can isolate this issue to WSL that would be helpful too i.e replace any WSL instance with a native Linux and see if it changes anything.

@ketozhang
Copy link

ketozhang commented Mar 27, 2018

@sunilmut No worries it's solved. The issue is parallel to the original issue; I was unable to SSH into a WSL server using public ip instead of local ip.

This is likely a ISP or setup problem not a WSL bug and it is the ISP's rental equipments.

@gkenaley
Copy link

gkenaley commented Jun 3, 2018

Reinstalling sshd (openssh-server) fixed this for me. No firewall changes required:

apt-get remove openssh-server
(reboot WSL)
apt-get install openssh-server
systemctl enable ssh.service
systemctl restart ssh.service

From the local Windows 10 Cygwin prompt:
ssh linuxruser@127.0.0.1

@charlchi
Copy link

  1. Have port forwards set up on your router for whatever port you're using
  2. Make an inbound rule for said port in Windows Firewall > Advanced Settings
  3. If you have an anti-virus, also be sure to check it's firewall settings.
  4. Ensure the ssh service daemon is actually running with a call to top. On the right side there should be a process listed as sshd. If there is none: service ssh start

@philiptolk
Copy link

My issue was that the domain had been moved to cloud front and I needed to use the direct IP address instead of the domain name.

@jcbowers
Copy link

jcbowers commented Sep 3, 2018

I received a "Resource temporarily unavailable" error because my subnet did not have a route to an Internet Gateway

@andrerpena
Copy link

andrerpena commented Feb 23, 2019

I'm so stupid. I just had this problem because I installed Nginx in the server and it blocks SSH by default. You have to sudo ufw allow ssh

@AleksandrHovhannisyan
Copy link

I like that this is still a problem.

thisisfine.gif

@bitcrazed
Copy link
Contributor

@AleksandrHovhannisyan - sorry - what problem? ssh should work fine.

@AleksandrHovhannisyan
Copy link

ssh always gives me a port 22 timeout/error on both WSL and PowerShell.

Maybe it's not a Windows thing? Idk. The only time I've been able to ssh into another machine is when that machine was a virtual machine in VirtualBox.

@arjunamrith
Copy link

arjunamrith commented May 13, 2020

@AleksandrHovhannisyan @bitcrazed Every time I update windows I have a problem with SSH to my ec2 instance. I tried most of the solutions in this issue and it still does not work. The solution that seemed to work for me the longest time was to add 8.8.8.8 as a NameServer in the /etc/resolv.conf file in WSL and this configuration had to be done everytime wsl is booted. This does not work for me since the latest update.

Also its worth noting that I am connecting to my server through a VPN (which is a requisite).

@bitcrazed
Copy link
Contributor

Hey Arjun: It's very difficult to provide assistance with zero details about your environment, what you're seeing, repro steps, etc.

Also, please don't comment on closed threads - there are several other open VPN & SSH threads that're likely to get more attention. If none of these describe your scenario, please file a new issue with as much info as you can. Thanks.

/cc @craigloewen-msft

@aminPial
Copy link

aminPial commented Jun 23, 2020

do this: sudo ufw allow ssh or if you wanna be specific on ssh port(22) do sudo ufw allow 22.
To check if firewall added properly: sudo ufw status.

This thing actually happens when you do sudo ufw enable and forget to add a ssh or port 22 firewall.

@asal1514
Copy link

Hi all, Maybe someone helps me to fix this issue: I tried to connect via ssh in Ubuntu(WSL) but I got the following error:

OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 10.1.1.9 [10.1.1.9] port 22.
debug1: connect to address 10.1.1.9 port 22: Resource temporarily unavailable
ssh: connect to host 10.1.1.9 port 22: Resource temporarily unavailable

Then I tried to disable ufw or open it for port 22 : but I got the following error: sudo ufw allow 22/tcp
WARN: initcaps
[Errno 2] iptables v1.8.4 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

and

sudo ufw status
[sudo] password for sara:
ERROR: problem running iptables: iptables v1.8.4 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

I have upgraded the kernel fully but I got same error again: sudo iptables -L
iptables v1.8.4 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

** we use an open VPN credential to connect and my system ssh public key has been set on the server.

many thanks,
Sara.

@HeshamZwayyed22
Copy link

I faced the same problem suddenly after ssh was working fine, then I found that windows made an update which affected my Hyper-V virtual switch configuration .. somehow after some trails I was able to fix it mainly by disabling and removing one of the Hyper-V virtual switches added after the windows update

@tolga-balci
Copy link

tolga-balci commented Sep 29, 2022

This is still a problem.
I cannot ssh to my Ubuntu 22.04 machine running on Hyper-V (Windows 11, both host and guest have the latest updates.)

tolga@host:$ scp datafile.csv tolga@192.168.0.41:/home/tolga/Desktop
ssh: connect to host 192.168.0.41 port 22: Resource temporarily unavailable

tolga@host:$ ssh tolga@192.168.0.41 -vvv
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.0.41 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.0.41 [192.168.0.41] port 22.
debug1: connect to address 192.168.0.41 port 22: Resource temporarily unavailable
ssh: connect to host 192.168.0.41 port 22: Resource temporarily unavailable

Checks so far:

  1. Allowed ssh on ufw
  2. Restarted ssh
  3. Reinstalled openssh-server
  4. Rebooted guest

Edit: corrected command view, added verbose output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests