181

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.

7
  • 4
    Possible duplicate of Where is the Windows bash directory in Windows?
    – phuclv
    Aug 8, 2016 at 6:38
  • (I have suggested to close phuclv's linked question as dupe in reverse-chronological order as this question is both more general and has far better and more up-to-date answers.)
    – Bob
    Aug 28, 2019 at 5:00
  • Perhaps it's obvious to some, but in reality you really don't need to have Win access to the linux files. As folks clearly state below, doing so is Dangerous. Instead, you can do most everything you need from the bash shell. For example, to copy your id_rsa file to you windows section, you can do that from bash via /mnt/c/user/<USERNAME> yadda yadda. I made a symbolic link to my Win Desktop in my Bash home and I can move, delete, etc from within bash. Feb 17, 2020 at 23:22
  • 4
    @mikemtnbikes Copying it won't keep it in sync. A symbolic link between windows and linux? Does that even work? If it does, that sounds equally dangerous. I only intended to read the files, but regardless, we have \\wsl$ now which is perfectly safe.
    – mpen
    Feb 18, 2020 at 3:34
  • 1
    posting it here for visibility as I was misled by nearly all examples below. To read WSL ssh config or other useful file from your VS Code settings, you must use forward slashes: //wsl$/<distro>/home/<username>/.ssh/config. Also, the distro name needs a version number, not just "Ubuntu" or "Debian". Type wsl -l in cmd to confirm what you've got.
    – Fons MA
    Jun 3, 2021 at 1:58

14 Answers 14

98

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

enter image description here

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.

17
  • 2
    Sir, Is this 9P file server feature stable for normal users? If not then it may be better to add a warning about using unstable insider builds. Many users may not familiar with it. One interesting fact though, your answer contains blogs from 2016 and 2019, ~3 yr ;)
    – Biswapriyo
    Mar 1, 2019 at 18:28
  • 1
    @biswaprio.it is made VERY clear in the manual steps one has to complete to join the Insider program that these releases are literally weekly drops of the next version of Windows as it's being built. And yes, the 9P server will be stable for general users in the mainstream OS release it arrives within. And yes, the fact that it's taken us this long to build & start delivering a decent solution here should give you some idea about how tricky it wss for our small team to prioritize and to engineer. Mar 7, 2019 at 21:24
  • 3
    I have been trying out this command from Ubuntu with every update of my system since I first heard this was released. My explorer always goes to my Documents folder. And I have not yet found out any steps to "enable" this feature.
    – Axeman
    Mar 16, 2019 at 2:52
  • 7
    Similar situation to Axeman, when I run explorer.exe . it opens the System32 folder. @RichardTurner Where are the manual steps?
    – Chris
    Mar 20, 2019 at 19:33
  • 1
    It's been working great for me. I didn't change any settings. Goes into some \\wsl$ folder, just like the article says. I think I'm on slow-track Insider edition though.
    – mpen
    Mar 29, 2019 at 0:22
87

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.

https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

9
  • 1
    Thanks! Thought I was going crazy trying to follow the old instructions, I didn't even have a lxss folder.
    – Alex S
    Feb 20, 2018 at 2:13
  • 1
    Is this information still true? I cannot find such folder on my Windows 10. May 14, 2018 at 7:13
  • 13
    WE STRONGLY RECOMMEND THAT YOU DO NOT SPELUNK INTO THE DISTRO ROOT FOLDERS FROM WINDOWS. IF YOU DO, DATA LOSS AND/OR CORRUPTION IS HIGHLY LIKELY: Please read this post for more details: blogs.msdn.microsoft.com/commandline/2016/11/17/… Mar 1, 2019 at 18:15
  • 2
    "I doubt anyone would try to manipulate or change files that way". Why do you think I shouted the advice above? We hear from people multiple times a week cool have ignored or not read this advice and end up corrupting the files in their root folders. Heck, there are tools that replace your (beta)distros files that often cause this too. Mar 7, 2019 at 21:17
  • 2
    I browsed to a folder I had created via Ubuntu WSL in Explorer and as a result it irreversibly broke permissions...so yeah, I would not recommend doing this! Mar 29, 2019 at 17:55
81
\\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

7
  • 17
    also woth noting, Running \\wsl$ will allow you to navigate to the correct installation & path using explorer (If you have multiple distros
    – Tricky
    Dec 19, 2019 at 11:49
  • 3
    \\wsl$\Ubuntu-20.04
    – jrsalunga
    Jul 3, 2020 at 10:17
  • 3
    when I entered \\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...
    – TmTron
    Jul 17, 2020 at 13:38
  • 9
    This answer should be marked as the 'official' answer as using the \\wsl$ share is the only route to safely edit WSL Linux files from Windows
    – cyberspy
    Oct 27, 2020 at 20:44
  • 1
    In VSCode I needed to enter path in ProjectManager extension, I had to use forward slashes like this: //wsl$/Ubuntu-20.04/home/<myuser>/ May 17, 2021 at 22:11
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.

3
  • 1
    Even simple text files? What are the pitfalls?
    – mpen
    Aug 8, 2016 at 17:01
  • 3
    Every file that resides on a Volfs folder (like /home) has Extended Attributes that store the Linux permissions of that file. If you edit that file on a windows editor then those attributes are lost and file will disappear from bash. You can read more here: blogs.msdn.microsoft.com/wsl/2016/06/15/wsl-file-system-support
    – onoma
    Aug 8, 2016 at 21:56
  • 4
    Sounds like that ought to be a bug. Windows either shouldn't give us access to those files, or give us read-only access, or they should intercept the write calls to the linux files and just not modify the attributes. Thanks for the tip. I only wanted to read the files, so hopefully that's not a problem.
    – mpen
    Aug 8, 2016 at 22:00
8

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
3
  • 2
    It seems the path changed since the official FCU update. Oct 21, 2017 at 8:08
  • 1
    @Briefkasten I just updated to FCU and my files are still there. Created a new file under Bash just to make sure. Did you upgrade WSL or something?
    – mpen
    Oct 24, 2017 at 6:02
  • 3
    @John D The WSL is located in the Package Folder where the App will be installed. For me it is: C:/Users/{username}/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/ Cont. to github.com/Microsoft/WSL/issues/402#issuecomment-321853125 Oct 28, 2017 at 8:15
7

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.

1
  • 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"?
    – Timo
    Dec 6, 2021 at 19:35
6

If you open Windows Explorer e type the path \\wsl$ it will list all your installed Linux distributions.

3
  • 2
    This information was already suggested in October 2019
    – Ramhound
    Jun 18, 2020 at 3:27
  • @Ramhound, the other post takes you to a specific point in an specific filesystem. My explanation is simpler, less confusing and will make the user choose the correct docker container.
    – neves
    Mar 13, 2021 at 21:42
  • does not matter when this info was mentioned but it is the most quickest zero configuration method to access the files in WSL, no third party tools needed, the location comes online when bash starts, Mar 24, 2021 at 12:06
4

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”?

0
4

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

3

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.

1
  • 3
    Nice solution! For current Windows 10 it's subst L: $env:LOCALAPPDATA\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs Jan 22, 2018 at 18:05
3

This worked for me using Powershell

cd  Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu-20.04\home\username
3

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.

2

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"

2
  • What is the advantage of this over going to the files directly?
    – mpen
    Aug 1, 2017 at 22:21
  • 1
    The files have metadata attached which may be lost when accessing the directly with applications that do not understand the metadata.
    – mlk
    Jun 18, 2018 at 9:12
1

From RUN (WindowsKey + R) you can type \\wsl$ and it will give you all your wsl installations.
This applies for WSL2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .