Insufficient permissions in vscode

故事扮演 提交于 2020-12-27 08:54:47

问题


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


回答1:


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




回答2:


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

sudo chmod -R 777 testproject



回答3:


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



回答4:


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



回答5:


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



回答6:


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



回答7:


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




回答8:


Move all project files to new folder ;)




回答9:


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

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




回答10:


Give permission to your project folder like below

sudo chown -R $USER:$USER your_project_folder_name



回答11:


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.




回答12:


Try open the vs code with run as administrator



来源:https://stackoverflow.com/questions/51674627/insufficient-permissions-in-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!