13

I am new to WSL and have installed VS code natively on Windows 10 with the installer. Currently, when I try to run VS Code command code from WSL, I receive the following message:

bash: /mnt/c/Users/user/AppData/Local/Programs/Microsoft VS Code/bin/code: Permission denied

Also, when I try to run VS Code Server for WSL, I am getting a similar message.

[2020-06-29 17:41:41.640] Launching C:\windows\System32\wsl.exe -d Ubuntu sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" cd9ea6488829f560dc949a8b2fb789f3cdc05f5d stable .vscode-server 0  ' in c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.4}
[2020-06-29 17:41:41.779] sh: 1: /mnt/c/Users/user/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.4/scripts/wslServer.sh: Permission denied
[2020-06-29 17:41:41.780] VS Code Server for WSL closed unexpectedly.

I have tried configuring the permissions for wsl @ wsl.conf:

[automount]
enabled = true
options = "uid=1000,gid=1000,umask=022,fmask=11,metadata"

Not sure if this is relevant, but I am able to run code from Windows Powershell.

I am currently using Microsoft Windows 1909 (OS Build 18363.836) with WSL v1.

Any help will be appreciated, thanks in advance!

9 Answers 9

8

It has to do with your /etc/wsl.conf. Change the contents of the file to:

[automount]
enabled=true
root = /
options="metadata,uid=1000,gid=1000,umask=002,dmask=002,fmask=002"

umask,dmask, and fmask all have to do with permissions. A pretty good explanation of them can be found here : https://askubuntu.com/questions/429848/dmask-and-fmask-mount-options#:~:text=fmask%20and%20dmask%20are%20mount,files%20and%20dmask%20to%20directories

Sign up to request clarification or add additional context in comments.

2 Comments

I do not have this file on my wsl installation
@paradox you should create it, if it does not already exist.
7

None of the previous answers worked for me. Instead after a lot of trial and error, I discovered that the code.exe was set in a way that it was being run as Administrator. This is what prevented it from running in the WSL. Find the VC Code executable, and ensure it doesn't have the admin Shield on it's icon.

2 Comments

My problem, and solution!
I had the opposite problem: my vscode was running as regular user but the files I was trying to edit was owned by root user. I fixed the file ownership (using sudo chmod -Rv $USER:$USER . in in WSL) and then VSCode was then able to edit and autosave them.
6

Run wsl.exe or PowerShell as an Administrator Runs as Admin Windows

1 Comment

Thanks for the answer, unfortunately, this didn't work for me.
2

After removing the folder ~/.vscode-server the command code . worked again.

$ sudo rm -R ~/.vscode-server

Comments

1

Solution that worked for me was described here: https://github.com/microsoft/vscode/issues/90164

fixed by setting remote.WSL.fileWatcher.polling in VSCode settings to True

Comments

0

Maybe for someone will helpfull... For example i have mistake like this:

$ code . /c/Users/admin/AppData/Local/Programs/Microsoft VS Code/bin/code: line 61: /c/Users/admin/AppData/Local/Programs/Microsoft VS Code/Code.exe: Permission denied

My error resolving was by click right button mouse on icon VS Code and chosen settings then "compatibility" tab and finaly disabled "run the program as an administrator"

Comments

0

I solved it by putting my Ubuntu user in the www-data group. I edited the /etc/group. That www-data group is the one in my configuration belongs to Apache2. Hope this helps.

Comments

0

Perhaps your files/directory does not have the right permissions. Run the following command:

sudo chmod 666 -R ./

This command will let other users (other than root) read/write to the files. -R is for recursive. This will modify all the files/folders inside that directory with new permisssions. You can run ls -l command to see the current permissions and the ones after ruuning the command.

Comments

0

The error indicates the code binary residing in the Windows volume isn't executable for your Linux distribution because of changed automount options.
You need to find where the code, code-tunnel.exe (and probably other similar files) are, and make them executable by running cmod +x code (and for other files discovered in the previous step) from your WSL terminal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.