42

I'm trying to make WSL2 work for my web projects development and this is driving me crazy!

Basically, i have two options. 1. Save my project files into c drive and access those with WSL (which makes the responses extremelly slow) 2. save my project files into /home/ which makes the project run super smooth, but i'm unable to edit those files with VSCode.

The error that is what follows:

Failed to save 'DefaultSeeder.php': Unable to write file 'vscode-remote://wsl+ubuntu-20.04/home/lucas/Projetos/API/src/database/seeds/DefaultSeeder.php' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/lucas/Projetos/API/src/database/seeds/DefaultSeeder.php')
Lucas Pacheco
  • 761
  • 1
  • 6
  • 10

7 Answers7

79

Here is another command to provide your user with sufficient permissions to write to files:

sudo chown -R myuser /path/to/folder

From https://github.com/microsoft/vscode-remote-release/issues/1008

ansona
  • 791
  • 4
  • 2
17

Well, turns out I was being stupid and posted a stupid question.

After many hours trying to make this damn thing work, I was able to do so, by setting the ownership of the folder to my user.

Here is the shell snippet to change the ownership to the current logged in user:

$ sudo find /~~folder-path~~/ -type d -user root -exec sudo chown -R $USER: {} +~
jkinkead
  • 4,101
  • 21
  • 33
Lucas Pacheco
  • 761
  • 1
  • 6
  • 10
17

This solved it for me

sudo find /home/ -type d -user root -exec sudo chown -R $USER: {}  \;
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
ali Saen
  • 311
  • 1
  • 3
  • 9
  • 3
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 22 '21 at 07:32
  • 1
    Thanks, that's saved me from hours digging – Douglas Roos Sep 07 '22 at 12:16
  • Thanks!!! I've been digging for a long time. – Maxim Paladi Dec 29 '22 at 10:16
  • This worked for me but it will be great if someone can explain what it does exactly, because it seems better than the solution above. – paradox Feb 26 '23 at 05:28
6

I had the same problem and spent hours to find this working solution.
For me, it seems to be right one because it doesn't produce problems with 1. too generous file permissions sent to git afterwards and 2. change ubuntu config to fit windows environment (coupling to windows user).

I found the source of this solution on github. Thanks to saltazaur! https://github.com/microsoft/WSL/issues/4260#issuecomment-729594527

Steps to solve the problem:

  • Reset (or reinstall) the Ubuntu distro via Windows "Programs and Features"
    Note: If you have data in your home directory already, copy it to windows before
  • Open Ubuntu & follow initial setup (create user)
  • Add file "/etc/wsl.conf" with:
cd /etc
sudo touch wsl.conf
sudo nano wsl.conf
  • copy and paste the content from microsoft docs
  • save with CTRL+X > "Y" > ENTER
  • restart wsl (or windows, to be sure ;))

At next startup of ubuntu, the settings in wsl.conf will be applied.

The important part in this case is the following line:

options = "metadata,umask=22,fmask=11"

It sets, that all newly created files will use umask 22 (chmod 775) and fmask 11 (chmod 644)

This settings also applies for IDEs like VSCode & PHPStorm.
Happy coding - finally! ^^

wamaro
  • 113
  • 1
  • 2
  • 9
6

In my case, I cannot edit/delete any file directly by File Explorer too, not just VSCode.

After opening Ubuntu 22.04.1 LTS on Windows, run

sudo chown -R my_username my_folder

Note the my_username is the username in the Ubuntu.

This solves my issue.

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
0

I've managed to solve this issue as follows:

  • "Run as administrator" the VS Code
  • and then open folder -> locate the working folder.

It worked fine for me.

Iyad
  • 61
  • 1
  • 6
0

Ownership issue: It's possible that you don't have ownership of the files or directories in your project. In this case, you can try changing the ownership of the entire project directory to your user account using the chown command. Run the following command:

  > sudo chown -R your_username:your_username /path/to/folder

E.g.: Let's say your_username: ABC then hit below command

  > sudo chown -R ABC:ABC /home/lucas/Projetos