117

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.

  • 4
    Possible duplicate of Where is the Windows bash directory in Windows? – phuclv Aug 8 '16 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 '19 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. – mikemtnbikes Feb 17 at 23:22
  • 1
    @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 at 3:34
  • @mpen my limited understanding is that you can mess things up using Windows Explorer (or any non-ubuntu shell program) to access WSL, but not the other way around (That is, I believe using ubuntu to access WSL files or std win files shoudl be fine since the shell should be WSL 'aware'). Thus, I expect you should be able to make a symbolic link within the shell from the WSL to non-WSL directories and vice versa. (Please note the caveats and let me know if you try making links and, if so, what the outcome is.) – mikemtnbikes Mar 3 at 9:34

11 Answers 11

62

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.

| improve this answer | |
  • 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 '19 at 18:28
  • Ooh, that is exciting news!! Thank you for sharing! – mpen Mar 4 '19 at 7:05
  • 1
    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 '19 at 2:52
  • 6
    Similar situation to Axeman, when I run explorer.exe . it opens the System32 folder. @RichardTurner Where are the manual steps? – Chris Mar 20 '19 at 19:33
  • 1
    @AndrewKoster - please note that I pointed out above that you'll need 'Win10 1903 (and later)' to get the newest Explorer integration with WSL distros. – Richard Turner Aug 22 '19 at 21:29
74

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/

| improve this answer | |
  • 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 '18 at 2:13
  • 1
    Is this information still true? I cannot find such folder on my Windows 10. – Bruno Finger May 14 '18 at 7:13
  • 9
    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/… – Richard Turner Mar 1 '19 at 18:15
  • 1
    "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. – Richard Turner Mar 7 '19 at 21:17
  • 1
    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! – SamAndrew81 Mar 29 '19 at 17:55
28
\\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

| improve this answer | |
  • 5
    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 '19 at 11:49
  • \\wsl$\Ubuntu-20.04 – jrsalunga Jul 3 at 10:17
  • 2
    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 at 13:38
  • 2
    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 at 20:44
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.

| improve this answer | |
  • 1
    Even simple text files? What are the pitfalls? – mpen Aug 8 '16 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 '16 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 '16 at 22:00
9

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
| improve this answer | |
  • 2
    It seems the path changed since the official FCU update. – Briefkasten Oct 21 '17 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 '17 at 6:02
  • 2
    @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 – Briefkasten Oct 28 '17 at 8:15
6

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.

| improve this answer | |
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”?

| improve this answer | |
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.

| improve this answer | |
  • 3
    Nice solution! For current Windows 10 it's subst L: $env:LOCALAPPDATA\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs – Andreas M. Oberheim Jan 22 '18 at 18:05
3

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

| improve this answer | |
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"

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

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

| improve this answer | |
  • This information was already suggested in October 2019 – Ramhound Jun 18 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.