Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

VS Code cannot save files in a WSL2 project folder: Insufficient permissions or EACCES

Your error

Failed to save 'web.php': Unable to write file 'vscode-remote://wsl+ubuntu/home/me/app/routes/web.php' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/me/app/routes/web.php')1 more line it can show

Fix it fast

Most common cause, 1 of 2

The file was created as root by sudo or by a container

Hand the project back to your user, then keep creating files through the sail commands rather than a root shell or sudo.

Fix
sudo chown -R "$(id -un)":"$(id -gn)" ~/app

# from now on
./vendor/bin/sail artisan make:model Invoice
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

"Failed to save" with "NoPermissions (FileSystemError): Error: EACCES: permission denied" in VS Code on WSL2 means your Linux user may not write the file. In Laravel and Docker projects it was usually created as root: by sudo, sail root-shell or a container command not run as sail. Give the files back with chown and create new ones as yourself.

  • Applies to VS Code with the WSL extension, WSL 2 (Ubuntu 24.04), Laravel Sail 1.71
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

In the WSL terminal, print your user and list every project file that belongs to someone else. Files owned by root point to cause 1; a clean list while saves still fail from a Windows window points to cause 2.

Run this first
id -un
find . \( -path ./vendor -o -path ./node_modules \) -prune -o ! -user "$(id -un)" -print | head -n 20

Then find the line you see in this list and open its fix:

  1. 1The file was created as root by sudo or by a containerThe find command lists files owned by root, often new ones from artisan make commands, composer or a queue job
  2. 2The folder is open from Windows through \\wsl.localhost, not in a WSL windowThe VS Code status bar shows no WSL indicator, the path in the title starts with \\wsl.localhost or \\wsl$, and the message offers Retry as Admin

What does the error look like?

  • Failed to save 'web.php': Unable to write file 'vscode-remote://wsl+ubuntu/home/me/app/routes/web.php' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/me/app/routes/web.php')
  • Failed to save 'web.php': Insufficient permissions. Select 'Retry as Admin' to retry as administrator.

Cause 1 of 2

The file was created as root by sudo or by a container

You seeThe find command lists files owned by root, often new ones from artisan make commands, composer or a queue job

Check

VS Code's EACCES or Insufficient permissions error on a WSL project means the file belongs to root and your user has no write bit on it. Laravel Sail runs its commands as the sail user, whose id it sets to yours, so files from sail artisan are yours. Files written through sail root-shell, with SUPERVISOR_PHP_USER set to root, through a docker compose exec that does not pass -u sail, or with sudo are not.

Check
ls -l routes/web.php app/Models/ | head

Fix

Hand the project back to your user, then keep creating files through the sail commands rather than a root shell or sudo.

Fix
sudo chown -R "$(id -un)":"$(id -gn)" ~/app

# from now on
./vendor/bin/sail artisan make:model Invoice

Verify

The ownership scan now comes back empty, and VS Code saves the file without a prompt.

Verify
find . \( -path ./vendor -o -path ./node_modules \) -prune -o ! -user "$(id -un)" -print | head -n 5

Confirmed by github.com

Did this fix it?

Cause 2 of 2

The folder is open from Windows through \\wsl.localhost, not in a WSL window

You seeThe VS Code status bar shows no WSL indicator, the path in the title starts with \\wsl.localhost or \\wsl$, and the message offers Retry as Admin

Check

Insufficient permissions with a Retry as Admin button on a WSL folder means VS Code is running on Windows and writing over the \\wsl$ share. Windows apps reach Linux files as the distribution's default user, so a default user other than the owner of the project, or a file that user may not write, makes the save fail, and running VS Code as administrator does not change the Linux user.

Check
# in the WSL terminal
whoami
cat /etc/wsl.conf

Fix

Open the project in a WSL window, from the project folder in the WSL terminal, so VS Code works as the Linux user who owns the files. If the distribution starts as the wrong user, set the default user in /etc/wsl.conf and restart WSL.

Fix
cd ~/app && code .

# /etc/wsl.conf
[user]
default=me

# then, from PowerShell
wsl --shutdown

Verify

The window shows the WSL indicator in the bottom left corner, and the file saves.

Verify
code .

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Keep Laravel projects inside the Linux file system and open them only with code . from the WSL terminal.
  • Run artisan, composer and npm through sail, never through sail root-shell or sudo, unless a step truly needs root.
  • Leave SUPERVISOR_PHP_USER at sail unless a container error requires root, and fix ownership again if you change it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.