Insufficient permissions in vscode

Visual Studio-Code

Visual Studio-Code Problem Overview


How do I resolve the vs code Insufficient permission issue when saving a file

I've given appropriate permissions to code directory: chown -R me:staff my-app/

But when I open vscode and try to save a file it says "Insufficient permissions, Retry as admin"

If I launch vscode with sudo from cmd line sudo code . then I dont get that error but then the autocompletion extensions dont seem to work

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

Change the permission level of your project directory, for example:

sudo chmod -R 777 testproject

Solution 2 - Visual Studio-Code

Try this code:

sudo chown -R username directory_name

where,

  • username is the username of the user of the laptop you want to give access for
  • directory_name is the name of the directory whose permissions you want to change

Solution 3 - Visual Studio-Code

Try with the below command(For linux/mac)

sudo chown -R abhinav-kumar my-app

Let’s break this down.

  • sudo – admin rights must be used since we are dealing with a folder that belongs to another user

  • chown – the command for changing ownership

  • -R – the recursive switch to make sure all child objects get the same ownership changes

  • abhinav-kumar – the new owner of the folder

  • my-app – the directory to be modified

Solution 4 - Visual Studio-Code

Should I give you a fish? Nope.. that's is not right at all! I should teach you how to fish and it'll save you for a lifetime.

Dear anyone, the issue is all about access permission to that directory or even file sometimes. So you need to use chmod command to change access permission and we normally use access codes which work as a combination of three octal digits (0-7).

> The three chmod codes set permissions for these three groups in this > order: > > 1. Owner (you) > 2. Group (a group of other users that you set up) > 3. World (anyone else browsing around on the file system) > > Each digit of this code sets permissions for one of these groups as > follows. Read is 4. Write is 2. Execute is 1. > > The sums of these numbers give combinations of these permissions: > > 0 = no permissions whatsoever; this person cannot read, write, or execute the file > 1 = execute only > 2 = write only > 3 = write and execute (1+2) > 4 = read only > 5 = read and execute (4+1) > 6 = read and write (4+2) > 7 = read and write and execute (4+2+1)

Read more from this article

Hence, in your case you could try running sudo chmod 777 folder-name which I'm sure it's gonna work! But... It's not safe for use!!! keep it away from the reach of yourself! IT'S A RISK!..

I would suggest to try 755 to make it work. Or something different since you now understand what you're doing! (I mean to fish!)

Solution 5 - Visual Studio-Code

Please, don't use 777 for permissions, it's a security risk.

You must be the owner of all files and folders

In your project folder run (replacing <user> with your username):

chown <user>:<user> -R .

If any file is owned by root, then it'll require sudo.

All folders must have permission 755

find . -type d -exec chmod 755 {} +

All source code files must have permission 644

Let's start changing only the source files. As my project is a Python project, let's apply the change initially only for .py source files (change the extension to your source files):

find -name "*.py" -exec chmod 644 {} +

Done

Check if it works.

If this is not enough, you can additionally change permission of all project files to 644, but maybe this will change the permission for images and some executables.

So, being warned that you can change images and binaries permissions:

find . -type f -exec chmod 644 {} +

Solution 6 - Visual Studio-Code

You should add your User or the User who is currently logged in to the folder and grant Read and Write access.

enter image description here

Solution 7 - Visual Studio-Code

The two simplified steps i found useful are:

  1. cd to that directorycd /var/www/target-directory
  2. change ownership to home user where vscode has all write-read permissionschown $(whoami) -R .
  3. Then do code . to open current directory in vscode and everything should be working.

> $(whoami) - pipes the result of the current user for home to chown command. Its concise and direct.
> -R command instructs chown to recursively change sub directories in this directory

Solution 8 - Visual Studio-Code

You can just change the ownership of your project folder.

sudo chown -c -R $USER:$USER (project folder)

Explanation:

  • chown: change the ownership of files/directories
  • c: report all changes
  • -R: do this recursively (for all files/directories beneath the given one)
  • $USER:$USER: change the owner and the group that owns the entry to the user that issues the command (sudo preserves the values)
  • (project folder): name of the folder which contains project files

You can test those environment variables with the following commands

echo $USER
sudo echo $USER

Solution 9 - Visual Studio-Code

Give permission to your project folder like below

sudo chown -R $USER:$USER your_project_folder_name

Solution 10 - Visual Studio-Code

For me I had same problem am working on windows 10 OS

just from Project folder -> Properites -> UnCheck Read-Only in attributes

enter image description here

Solution 11 - Visual Studio-Code

It looks like you somehow changed file ownerships in your home directory.

One way to correct this without endangering your system is

sudo chown -c -R $USER:$USER $HOME

Explanation:

chown: change the ownership of files/directories
-c: report all changes
-R: do this recursively (for all files/directories beneath the given one)
$USER:$USER: change the owner and the group that owns the the entry to the user that issues the command (sudo preserves the values)
$HOME: do this with your home directory

You can test those environment variables with the following commands

echo $USER
sudo echo $USER
echo $HOME
sudo echo $HOME

Solution 12 - Visual Studio-Code

This problem can be solved by changing the permissions of the project user to yourself.

However, if you change the permissions of a file, when you are developing a team, you can end up pushing even the permissions of the file to git.

If this happens, you may be warned by the team.

So, it would be better if you change the permissions of your local project folder and at the same time ignore the push of file permission changes to git.

This way, files with changed permissions won't be published online.

$ sudo chown -R userName /Users/userName/projectName
$ cd /Users/userName/projectName
$ git config core.filemode false
$ git config -l | grep filemode

Verify that core.filemode = false

about

git config core.filemode is set to true by default, and if it's not set to false, it will automatically convert to 644 if the permissions are set to 755

【Vscode】How to solve the problem when a file cannot be updated due to lack of permissions in vscode

Solution 13 - Visual Studio-Code

On windows 10 my Antivirus was the reason for this error to happen.

I had to add the folder where the file I wanted to save was to the excluded folder of my Ransomware protection.

Solution 14 - Visual Studio-Code

On Windows10, I solved adding "modify" permissions (to "authenticated users") to the project folder.

Solution 15 - Visual Studio-Code

> Insufficient permissions. Select 'Retry as Sudo' to retry as > superuser.

In Ubuntu 20.04 try these commands to give the right permission to your files and folders:

cd /PATH/TO/YOUR/FOLDER
sudo chown -R $USER:www-data .
sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;

Then try to save your files again.

Solution 16 - Visual Studio-Code

I encountered this error after executing sudo git pull on ubuntu, The issue was solved by Changing the file/directory persons for the owner, group and others for all the files and the folders for the project by running sudo chmod -R 770 projectFolder don't run sudo chmod -R 777 projectFolder for security reasons

Solution 17 - Visual Studio-Code

This is because you are not running VS Code as administrator. So VS Code does not have permission to save files.

You should always run VS Code as administrator. To do this, go to the folder where you installed it. By default, VS Code is installed under C:\users\{username}\AppData\Local\Programs\Microsoft VS Code .

Find the file "Code.exe" and open properties, go to the tab "Compatibility" and check the field "Run this program as administrator".

This method worked out well for me.

Solution 18 - Visual Studio-Code

Try open the vs code with run as administrator

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAngad DubeyView Question on Stackoverflow
Solution 1 - Visual Studio-CodeJ.S. PetersonView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeMohit SinhaView Answer on Stackoverflow
Solution 3 - Visual Studio-Codeabhinav kumarView Answer on Stackoverflow
Solution 4 - Visual Studio-CodedilungasrView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeRael Gugelmin CunhaView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeCyberView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeAndrew MititiView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeMahabubur RahmanView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeMusthafa MaView Answer on Stackoverflow
Solution 10 - Visual Studio-Codetaha mosaadView Answer on Stackoverflow
Solution 11 - Visual Studio-CodeSagar GhimireView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeRyosuke HujisawaView Answer on Stackoverflow
Solution 13 - Visual Studio-CodenantoniView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeVlandView Answer on Stackoverflow
Solution 15 - Visual Studio-CodePejman KheyriView Answer on Stackoverflow
Solution 16 - Visual Studio-CodeMundrukuView Answer on Stackoverflow
Solution 17 - Visual Studio-CodeSarvarView Answer on Stackoverflow
Solution 18 - Visual Studio-CodekbkView Answer on Stackoverflow