How do you get permission to drop files in your wsl2 instance from Windows?

How do you get permission to drop files in your wsl2 instance from Windows?

\\\\wsl$\Ubuntu-20.04

I tried to drop it in there, but I keep getting: "You need permission to perform this action."

I want to drop some files on my C drive to my WSL folder so I can access it from WSL without suffering a performance penalty when I try to run Docker from WSL from a folder that's in my C drive (Windows file system).


Solution 1:

I've never seen this documented (could be wrong), but in a quick test it appears to me that WSL prohibits access to any root-owned file or directory through the \\wsl$\<distro> share.

Some options:

  • Navigate to \\\\wsl$\Ubuntu-20.04\home\your_username and drop the files there

  • Create a directory under root / and chown to your user:

    cd /
    sudo mkdir project
    sudo chown $USER:$USER project
    

    You should be able to drop into that folder as well.

Alternatively, you can move the files from the command-line using the /mnt/c mount. For example:

cd ~
mv /mnt/c/Users/youruser/Documents/project/myproject .