This question answers how to access Windows files from Ubuntu Bash, but how can I do the opposite?
Specifically, I need to access my SSH key from Windows which is located at /home/mark/.ssh/id_rsa
under Bash.
This question answers how to access Windows files from Ubuntu Bash, but how can I do the opposite?
Specifically, I need to access my SSH key from Windows which is located at /home/mark/.ssh/id_rsa
under Bash.
PM for Windows Command-Line here:
Updated October 2019: Updating the response below to reflect the newly added ability to directly access distros' Linux files via the newly integrated P9 server in Win10 1903 (and later).
IMPORTANT: Spelunking through the Windows filesystem to access Linux files has and will continue to be unsupported and STRONGLY recommended against! To understand why, please read this post
So how does one access Linux files using Windows tools (e.g. notepad, VS/VScode, etc.)? Previously, you couldn't, but starting in Windows 10 1903 we (finally!) expose your distros' filesystems to Windows via a P9 fileserver. We've also published an in-depth video discussing how this works! You can also read a summary of this new feature in this blog post
Look forward to hearing how you get on with this feature. If you find any problems, please file issues on the WSL GitHub repo here: https://github.com/Microsoft/wsl.
explorer.exe .
it opens the System32 folder. @RichardTurner Where are the manual steps?
\\wsl$
folder, just like the article says. I think I'm on slow-track Insider edition though.
The location was actually moved in the latest release to :
C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\
See this GitHub issue from Microsoft/WSL #2578
As mentionned in the Issue above and the comments below, don't mess with these files from the windows os.
\\wsl$\Ubuntu\home\user\whatever
In the explorer or the Run widget (Cmd+R). Works like a normal network share and it's safe to manipulate files.
You can also map it to a drive or folder, just as any other network share.
Note: This is a new feature implemented in Windows 10 build 18342
\\wsl$
will allow you to navigate to the correct installation & path using explorer (If you have multiple distros
\\wsl$
in explorer, it did not show anything. In cmd I used use wsl -l
to see a list of distros and use the exact name e.g. \\wsl$\Ubuntu-18.04
. Once I have opened this location, also \\wsl$
starts to show it...
//wsl$/Ubuntu-20.04/home/<myuser>/
Commented
May 17, 2021 at 22:11
Yes but is not recommended to manipulate that folder from the windows explorer. If you want to copy, move, edit or erase files from the lxss folder you need to do it inside bash with command line tools. Only files that are on /mnt/* are really manipulable from the windows explorer.
Found it by searching my entire C drive. Files are here:
C:\Users\<username>\AppData\Local\lxss
e.g., my SSH key is here:
C:\Users\Mark\AppData\Local\lxss\home\mark\.ssh\id_rsa
In powershell
, use
cd ${env:appdata}\..\local\packages\canonical*\localstate\rootfs
then
ls
returns the same list of folders as
ls /
within bash on WSL.
cd ${env:appdata}\..\local\packages\canonical*\localstate\rootfs
does not work for the debian app
. How can I access debian files in powershell under the "wsl roof"?
If you open Windows Explorer e type the path \\wsl$
it will list all your installed Linux distributions.
As has been mentioned above by [onoma] files in WSL directories have attributes that would be gone if one manipulates it using explorer or text editor run under Windows system. The solution could be to start ssh-server in WSL (there might be a reinstall necessary) listening on localhost and then mounting WSL filesystem as a drive using, for example, win-sshfs or you can just use Bitvise SSH client to connect over ssh and manipulate files by sftp window. The topic has been partially discussed here: How can I SSH into “Bash on Ubuntu on Windows 10”?
I finally made a way to open explorer (and vscode) with actual correct folder context from inside WSL: https://github.com/andymule/wslwin
For example, after you install this, in linux (WSL) you would just cd /home/mark/.ssh/
and type explorer
, and it would open windows explorer at that location, whatever it is.
EDIT: this feature is being officially supported in WSL now, and you should no longer use my scripts
subst L: $env:LOCALAPPDATA\lxss
(for powershell)
or subst L: %LocalAppData%\lxss
(from cmd
)
This puts your Linux-subsystem filesystem-root /
on your L: drive.
You could also map just your home directory, or just whack %LocalAppData%\lxss
in an explorer window. Just don't try browsing L:\mnt\c or your brain might explode.
This worked for me using Powershell
cd Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu-20.04\home\username
I just discovered you can run powershell.exe
from linux and your linux console becomes a PowerShell console at the current directory. This is the best of both worlds as you never have to leave your linux console... which is where I spend most of my time. You can then type exit
to get back into linux world.
Im on Windows 10 Creators Update. I use SFTP NetDrive to mount the WSL filesystem into windows as as a network drive.
There are some Window sshFS ports that'll achieve the same thing.
You'll need to start the ssh daemon via "sudo service ssh start"
From RUN (WindowsKey + R) you can type \\wsl$
and it will give you all your wsl installations.
This applies for WSL2
\\wsl$
now which is perfectly safe.//wsl$/<distro>/home/<username>/.ssh/config
. Also, the distro name needs a version number, not just "Ubuntu" or "Debian". Typewsl -l
incmd
to confirm what you've got.