Visual Studio Code always asks for sudo permissions - macos

Ok, so I've got a problem with VSCode where every time I try to save a file it asks me for sudo permission and it's really annoying and I can't make folders or files directly in the IDE. Can please someone help me?
Screenshot from VSCode

The running instance of VS Code doesn't seem to have write permission to the file you wish to save.
Since the file is in the directory of user uteu3, first make sure that it is user uteu3 that has started VS Code (it probably is, if uteu3 is the user logged into the system).
make sure uteu3 is the owner of the file and change the permissions by opening a terminal and executing:
sudo chown uteu3 filename && sudo chmod 664 filename
(Replace filename with actual path+name to the file.)
If this doesn't solve the problem, please execute the following two lines in a terminal and provide the output:
ps aux | grep visual-studio-code
stat -f '%A %a %N' filename
Since you indicate that this happens repeatedly also with other files, maybe several of the file permissions in your home directory are problematic. In that case, consider trying to fix them all. See for example: Need to fix file permissions in a user's home directory
.

Related

Neofetch : acces denied folder .config

I need your help with an access issue with neofetch on my macOS.
Here the thing, I recently install neofetch on my terminal (oh-my-zsh), it works but, between the firts line (last login) and the logo that displays :
mkdir: /Users/'MYUSERNAME'/.config/neofetch/: Permission denied
/usr/local/bin/Neofetch: line 4476:
/Users/'MYUSERNAME'/.config/neofetch/config.conf: Permission denied
And I don't know why, of course, I did many types of research on google before asking you.
Do you have an idea?
You need to change the permissions for your config directory:
sudo chmod -R 666 /Users/YOURUSERNAME/.config
666 means Read-Write for all users.
Doing the same as garritfra did but with that last directory line you have there worked for me on a windows 10 machine though. It may work for the mac as well?
sudo chmod -R 666 /Users/MYUSERNAME/.config/neofetch/config.conf
Replace MYUSERNAME with whatever is shown in the error.
I was having the same issue and was able to solve this in the following way:
Open up Finder
Reveal hidden folders & files by pressing CMD+>+SHIFT
Locate the .config folder and right click it and click 'get info'.
Under the sharing & permissions section click the small plus and just add the entire Administrators group and remember to change the permissions to read & write for the entire group.
neofetch
Here is a bulletproof one-liner that solves the issue:
sudo chmod -R 710 $HOME/.config
Execute this command in a terminal session.
After restarting your terminal or, alternatively, sourcing your shell configuration file (assuming you have added the neofetch command to that file) with:
source ~/.zshrc
(replacing ~/.zshrc with the path to your shell configuration file if you are using a different one), the error prompt should disappear.
Note that this only gives 'execute' permission to the 'group' class. There is no need, as the currently accepted answer suggests, to give 666 or 777 modes as that needlessly makes your system less secure (not to mention even no. octal figures such as 666 don't even work as they fail to give the required 'execute' permission, which requires an odd number bit).
Modes such as 730, 750, and 770 will work, but unless something changes in neofetch's future update that demands it, it is unnecessarily too generous and I wouldn't advise it.
Finally, there is absolutely no reason to give users in the 'other' class any permission to the ~/.config directory (unless you have a very compelling reason to), and hence the last permission bit (3rd digit in the mode represented by octal numbers) should always remain 0.

VScode unable to save files inside my WSL2 home folder

I'm trying to make WSL2 work for my web projects development and this is driving me crazy!
Basically, i have two options.
1. Save my project files into c drive and access those with WSL (which makes the responses extremelly slow)
2. save my project files into /home/ which makes the project run super smooth, but i'm unable to edit those files with VSCode.
The error that is what follows:
Failed to save 'DefaultSeeder.php': Unable to write file 'vscode-remote://wsl+ubuntu-20.04/home/lucas/Projetos/API/src/database/seeds/DefaultSeeder.php' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/lucas/Projetos/API/src/database/seeds/DefaultSeeder.php')
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: {} +~
This solved it for me
sudo find /home/ -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! ^^
In my case, I cannot edit/delete any file directly by File Explorer too, not just VSCode.
After opening Ubuntu 22.04.1 LTS on Windows, run
sudo chown -R my_username my_folder
Note the my_username is the username in the Ubuntu.
This solves my issue.
I've managed to solve this issue as follows:
"Run as administrator" the VS Code
and then open folder -> locate the working folder.
It worked fine for me.

How to open file as root in GUI text editor on mac os

I need all my files in certain directory to be accessible only by root. So I do the chown and chmod commands to set privileges to 700 template where file owner is root. After that if I open files with nano everything works ok: if I run it with sudo I can see contents of files and edit it; if not root then I can see just an empty file which I can't edit or modify. Then I try to open files with Sublime2 as subl 1.txt. With or without sudo it just appears to show an empty file. Then I try sudo open 1.txt to open with the default TextEditor and then I see a message that I don't have permissions. The same if I try anything like sudo open -a (any other text editor from my apps) 1.txt the permissions message is shown. I've tried to google for gksu for mac but people say that sudo is enough. Please guys, any ideas on the topic are welcome. Thank you much!

Why can't I locate or navigate to this directory that my find command grabs?

I ran sudo find -L / -name .rvmrc and got:
/Library/Application Support/Comodo/Antivirus/Quarantine: Permission denied
and also: /dev/fd/3
When I try navigating to the directory I can only get to Application Support, and then from that directory when I run cd Comodo I get Comodo: No such file or directory But it is there if find is finding it right? or no? <<< I believe this is just the find process?
When I try to navigate to it using the finder I just get to Application Support, and Comodo is not there. I am displaying hidden files too. I am trying to remove all files of a certain type so I can get a new program to work properly. This find command suggests one of these files is still out there but I can not get to it.
For /dev/fd/3 why is this being matched? I'm no expert but I just did a quick google search and this is a file descriptor right? Does it even have content? How/Why could it match .rvmrc? When I try looking at it with cat I just get a bad file descriptor error. (Should I extract this into a separate question?)
Thanks for your help.
It looks like your user do not have sufficient privileges to access this Comodo directory.
Try ls -la "/Library/Application Support"/* . This should show who can access Comodo. If it is owned by yourself, then you can do a
chmod +rx "/Library/Application Support/Comodo/"
, then only view its content.
You might have access Quarantine because the find -L followed a link.
Edit
Once you have done this and cannot chmod anymore, then try to see who owns the dir:
ls -lad "/Library/Application Support/Comodo/Antivirus/"*

Unable to unlock file for editing in Xcode 4?

For some reason 2 of my files got locked and when I click the little lock icon in the upper right corner of the window it asks me if I would like to unlock, and doing so results in a "The file xxxx.h could not be unlocked" (Unlocking failed for an unknown reason). I have tried to restart Xcode, also tried to restart my machine with no help.
I am also unable to edit the files using BBEdit, I get the error "You do not have sufficient privileges to perform this operation (MacOS Error code: -5000)".
I'm running OS X Lion with Xcode 4.
Very strange as I have not made any changes to my system prior to this problem. Any help would be appreciated.
Open the file in any text editor. If the contents isn't text based you'll see a lot of gibberish. Ignore this, copy the contents. Open up a new text file. Paste the contents and save over the old file. This will copy just the contents of the file and ignore permissions.
What you're dealing with here is an ACL issue. If you ls -l the directory you'll see a little + on the end of the permission string:
drwxr-xr-x+ 4 eekyou staff 136 May 6 2011 eekyou.xcuserdatad
You can easily strip these off like so (in your project directory:
sudo chmod -R -E ./*
Hope this helps.
=]
The #eecue answer didn't help me. I user another Terminal command for complete removal of all ACL permissions:
sudo chmod -RN ./*
First check if the file is opened/locked by another program or user.
If it is not, the program probably crashed and failed to remove the flag, lookup the file and check with CMD+i if it is locked.
If it is not, permissions are probably wrong, so check the permission in the CMD+i dialog at the bottom, and apply them to everything in the enclosing folder (a .xcproject is a directory).
If this still doesn't work (like for me), there is a simple command line to unlock all files in a folder. ONLY do this if all the above steps have been checked / taken.
sudo chflags -R nouchg /Users/username/Development/GIT/MyProject
Replacing the project folder with your own project folder of course.
You may need to take ownership of the folder in which you wish to save your project. To do so, open up the console. Then type sudo chown $USER /path/to/your/project.

Resources