WSL: Can't SSH from WSL
- Your Windows build number: Microsoft Windows [Version 10.0.17134.1]
I have .pem file located on local disk C c/private-key.pem. And I have a soft link to it on Ubuntu subsystem ~/.ssh/private-key.pem -> /mnt/c/private-key.pem.
And when I’m trying to shh some remote machine from Ubuntu subsystem, I got :
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/home/artur/.ssh/private-key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/artur/.ssh/private-key.pem": bad permissions
Permission denied (publickey).
It was started after 1803 update for Windows.
I was trying to use chmod 400 or 600 for key on C drive and in ./ssh folder on subsystem. And was trying to set owner just to me and remove all other users from security panel on Windows for this file key. But i got Permissions XXXX for '/home/artur/.ssh/private-key.pem' are too open or Permission denied all the time.
Also I made a copy of key in Ubuntu subsystem which now located at c:\Users\<WindowsUserName>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\<UbuntuUserName>\.ssh\ and was trying to manage permissions and owners of it. And it fails too!
Can any body help me and explain how keys permissions should be configured on Windows and Ubuntu subsystem?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 27
- Comments: 44 (1 by maintainers)
Ok, setting it in
/etc/wsl.conffixed it for me. Just create the file if its not there and enter the following code:Then exit out of all the instances and relaunch WSL. All drives should be mounted with metadata now (see
mount -l)The blog post linked by @DarthSpock also contains other useful configs, so it’s worth a look.
Edit: @ArturChe I think this issue should be renamed include “chmod” or sth.
I followed the “metadata” procedure aforementioned,
“sudo chmod 600 key”,
and “sudo ssh -i key user@ip”
Solved for me…
Yeah there have been changes with build 17134. You want to review this blog: https://blogs.msdn.microsoft.com/commandline/2018/01/12/chmod-chown-wsl-improvements/ and see if that helps.
Here is the blog post on how to use the
-o metadataoption.Try configuring it in
wsl.confinstead of the command-line method. Here’s the blog: https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/This works for me!
.sshdirectory e.g.cp key ~/.sshsudo chmod 600 keySSH should work now.
I think I figured out why this happens. In the ssh source you can see that ssh only blocks overly permissive key files if they are owned by the current user. Since
DrvFsfiles used to be listed as owned by root, ssh would allow any key file from aDrvFsdrive. With the recent changes, the files are listed as owned by the current user, and suddenly the check applies.Luckily, as mentioned above, you can just remount with the
-o metadataoption and chmod your key files to be less permissive.using
ssh.exeinstead ofsshsolved it for meI don’t know why does @sunilmut CLOESED the issue, but I previously sad that I have tried to mount disk with -o metadata option and it DOES NOT resolving the issue!
@acehack @donglixp No one can help you without any additional information. Here is how a good comment to receive actual help looks like: -Include commands and output of what you did -include mount -l output
That way others can actually help you. “Stating it doesn’t work” helps no one and just discourages help because helpers need to painstakingly gather information from you. Give information so ppl can help you.
I have copied keys from Windows to Ubuntu subsystem and applied
chmod 400for each key file even withoutsudo. It works for me now. But I’d like to use previous behavior, when key placed on one location on Windows and on subsystem I manipulate with soft links only.@Biswa96 I haven’t try your proposal so far…
I followed this guide and succeeded in accessing my ec2 instance.
@iandk: It works for me now, I have reinstalled WSL 1 and now it works. My
/etc/wsl.conf:I got the same issue (too open permissions for the private key file located on the drvfs mount). The
metadataoption was already set, so this doesn’t fix the issue for me. What can be done? Should the private key be placed in user home (WSL) and used instead for ssh login?I’m having this same problem, none of the above fixed it, please re-open
You can use Task Manager to forcibly kill any Linux processes running including
initto forcibly tear the session down. Just be sure all instances are removed before creating a new one.Just to add to what @reijn90 said: Lately WSL requires some funky killall command to be properly restarted. See https://superuser.com/q/1126721. Unless someone here can enlighten us about the proper way of restarting, that is 😄