VScode unable to save files inside my WSL2 home folder VScode unable to save files inside my WSL2 home folder docker docker

VScode unable to save files inside my WSL2 home folder


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


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: {} +~


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! ^^