microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.45k stars 822 forks source link

Can't scp-ssh from my remote machine to my WSL OpenSSH server #1934

Closed ghost closed 6 years ago

ghost commented 7 years ago

My build is 14393.1066. I ran a search and made sure that wasn't discussed already, hence I report:

I ran scp /var/www/html/tiesto USER@IP:/mnt/c/Users/USER/Desktop/

As you can see, I try to copy the file "tiesto" from inside a remote machine, into my local WSL machine but the connection is timed out.

That doesn't happen when I try to scp'ing between two remote machines.


I might miss something here, maybe I need to setup something in WSL itself and it's not a bug at all? I really don't know.

MikeGitb commented 7 years ago

Was the ssh server actually running at that time? I don't think WSL starts any services automatically and you need to have open at least one WSL console window because otherwise the linux instance is shut down completely.

ghost commented 7 years ago

I believe it's not on (I didn't know it should be started in WSL), but anyway,

sudo service ssh start

initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused Starting OpenBSD Secure Shell server sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ssh/ssh_host_dsa_key Could not load host key: /etc/ssh/ssh_host_ecdsa_key Could not load host key: /etc/ssh/ssh_host_ed25519_key [ OK ]


According to Adam seering's answer here, I can ignore error about upstart but it seems that in this case I shouldn't and the links in that thread dealing with solutions are all dead/unreached.

MikeGitb commented 7 years ago

You can generate those keys via

sudo ssh-keygen -A
MikeGitb commented 7 years ago

This Blog post contains also a step by step guide of how to start an ssh server on WSL: https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/

I'm sure there is a better link somwhere, but that was the one I know of off-hand.

ghost commented 7 years ago

I created the keys but still get the upstat error. The link provided deals with Visual Studio but I don't use Visual studio... :| The only IDE I use as for today is Webstorm (most of the time I edit with Notepad++).

ghost commented 7 years ago

Okay, I took care of the error with the following fix by Canonical, but there is a problem.

cat > /usr/sbin/policy-rc.d <<EOF
#!/bin/sh
exit 101
EOF
chmod +x /usr/sbin/policy-rc.d
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl

Then my SSH server started just fine, and I logged in to my remote server and ran:

scp /var/www/html/tiesto USER@IP:/mnt/c/Users/USER/Desktop/

Yet still, sadly, the connection is timed out.

aseering commented 7 years ago

@Benqzq -- just as a test, could you try opening up a bash shell on your WSL machine and running ssh USER@localhost?

If that works, then the problem is most likely that some firewall program, firewall hardware device, or NAT device is blocking the connection between your Linux computer and your Windows computer. (Or you have the wrong IP address, etc.) In which case you should look closely at your firewall config and your network setup.

If that doesn't work, it probably means that the SSH daemon is not running, or is not running correctly. I would suggest looking at the SSH daemon's logs in /var/log/. Also try running ps ax | grep sshd to make sure that the daemon is running. It could also be a generic network-connectivity problem with WSL ( #1554 ). A handful of people have reported problems in recent builds that prevent any inbound connections to WSL processes. It seems to work for most people, though; the root cause of that issue still hasn't been found, though folks on the WSL team have been talking with people who have filed confirmed cases of this sort of issue to try to diagnose what's wrong.

ghost commented 7 years ago

@MikeGitb , isn't there another extra argument needed in sudo ssh-keygen -A? A DigitalOcean support programmer told me something extra is needed (though he didn't mention a specific argument).

@aseering , I get connect to host localhost port 22: Connection refused.

It seems I don't have a daemon log under /var/log.

For ps ax | grep sshd I get: 30 pts/0 S 0:00 grep --color=auto sshd

AFAIU, daemon isn't running. I should also note that in contrast to the first post, my current build is 15063.138 and moreover, I checked that eariler today, and another time after /lxrun /uninstall /full and reinstalling WSL... In both cases the exact same situation so yea, I guess it will be fixed with time. Can you please tell me where you think it is best for me to follow updates on this? Is there a twitter account or a WSL Google-docs like board of fixed and to-be fixed issues?

MikeGitb commented 7 years ago

I'm not aware of any additional parameters being necessary, but I'm not an expert in this.

FYI: The link I provided contains a step by step guide for setting up ssh that is independent of it's use with VS or SW in general, but it has been some time since I actually tried it myself.

ghost commented 7 years ago

@MikeGitb I read in the link, it also mentions sudo ssh-keygen -A without further arguments but I'll keep check it. Anyway, while VS is probably Visual Studio, what is SW?

MikeGitb commented 7 years ago

Sorry, wanted to write "for software development"

therealkenc commented 6 years ago

On recent WSL, say Creators Update 15063 and Ubuntu 16.04 sudo service ssh start should work alright. Previously you had to jump through some hoops per go-to post #300, but it should be easier now.