9

I'm currently using Ubuntu on Windows from the Microsoft Store.

To try some of my Python scripts, I copied and pasted them to the documents folder I can access with Ubuntu session :

C:\Users\[MyUsername]\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\[MyUsername]

But when I lauch the scripts, it returns "PermissionError: [Errno 13] Permission denied: '[folderName]". Is there a way to copy/paste files and folders from Windows session to Ubuntu folders without having to run chmod on all files ?

Thanks for your time

2
  • did you use sudo?
    – damadam
    Jun 26, 2018 at 14:34
  • 1
    @damadam brute forcing things with sudo is rarely a good idea Jun 26, 2018 at 14:42

6 Answers 6

10

You should not be manually copying data into the WSL installation from Windows - it will give you this permissions error when you do this. Rather, you should be copying from windows into WSL from within the WSL environment instead.

The Windows C drive is located at /mnt/c within WSL. If the scripts are located in C:\Users\username\My Documents\Python\ then you can do the following from within WSL to copy the scripts into the Ubuntu environment:

cp /mnt/c/Users/username/My\ Documents/Python/*.py ~

This will copy the data in and retain permissions so it works properly within the Windows subsystem for Linux. This also saves you from having to chmod typically.

2
  • Thanks for your help, it works (partially)! Indeed, when I edit one of my .py file with Sublime Text on Windows, it disables the reading, writing, executing rights on this file.
    – user844062
    Jun 26, 2018 at 18:04
  • @KanatheneΩ That's a side effect of editing the files on Windows; the only solution here is to re-copy your files down into your home directory for execution, and then execute them directly from your home directory. There's no solution that will work around this, however, because Windows doesn't support UNIX permissions that Ubuntu needs. You might want to, instead, just install Python for Windows and run them inside Windows at that point.
    – Thomas Ward
    Jun 26, 2018 at 18:05
0

I think this answer needs to be updated.

WSL wasn't allowing you before but it's now possible following this guide

You can simply move or copy/paste files inside one of these Linux directories, or through cmd or bash shell.

enter image description here

2
  • "this guide" send you to a website with an fatal error.
    – Aldo
    Jun 12, 2023 at 7:27
  • Dammit, that's bad! Jun 12, 2023 at 8:05
0

I wanted to move a file to the Ubuntu WSL working directory from the windows downloads folder using Ubuntu WSL command prompt as i had downloaded some files from an email but it denied access when i used the /mnt/c method. And the files get corrupted if you force copy them manually using the windows GUI. So what i did was that i installed firefox using my Ubuntu WSL command prompt. Opened the email using firefox (using the prompt ofcource) and downloaded the files which then went to a downloads folder in my Ubuntu WSL working directory. I got the files and the program to read the files was also installed using Ubuntu WSL so it worked for me. I am not sure whether the file reader if not installed using the Ubuntu WSL prompt will read the files for you because as far as i understand windows doesn't like to keep links with the Ubuntu WSL extension it provides. However if it helps, just email the files to yourself and download them using firefox and you have them.

0

You can move any file from any drive of Windows to only /home/user/ directory using Windows Explorer.

1
  • Can you provide more detail/explanation? Someone recently quoted your answer in a Super User answer, but this seems completely wrong. It has never, for at least 6 years, been the case that you can only copy files to /home/user in WSL (either 1 or 2). For many years now, WSL has created a \\$wsl\<distroname> share in which the entire filesystem is available, and whatever permissions your default user has to those folders will be used by Windows Explorer. Also, this question was specifically about WSL1, and copying to the Overlay Filesystem that WSL1 created. Mar 7 at 18:23
0

The solution is to setup an SSH server in your WSL Ubuntu instance, and then connect to it from Windows using a GUI program like FileZilla or WinSCP.
How do I connect to Ubuntu in WSL from Windows via SFTP?

0

To copy using Windows Explorer not just into default /home/user/ as Nishant Chandolia said you can broaden permissions of the destination folder, like

sudo chmod 777 destinationFolder

You must log in to answer this question.