VScode unable to save files inside my WSL2 home folder - laravel

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.

Related

Visual Studio Code always asks for sudo permissions

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
.

How to set permissions of certain folders to 777 on Mac

I need to set the permissions of just 3 specific folders (on my Mac) to 777
I went to CMND+i (get info) but the folder permissions seemed to be Read and Write - but this didn't seem to fix it.
I am trying to work out how to do this, because I am using MAMP on my Mac to try and run a localhost server to test a website. Reason; I am trying to run the script of a PHP website. It is asking me to change the permissions of certain folders in order to proceed with the 'install'.
I think the closest match to a possible answer is here:
Java: Create a new dir with 777 permissions on Mac
But, this appears to be Java. I assume that I need to be able to do this via either MAMP or Terminal. If anyone could please advise me which program/tool to use and what to type in, I'd be very grateful.
Thanks
I know how to do it in a terminal, to create "/some/directory/some/where" you can use -
# EDIT: 777 not 077.
mkdir -p /some/directory/some/where && chmod 777 /some/directory/some/where

XAMPP permissions on Mac OS X?

I installed XAMPP 1.7.3 on Mac OS X 10.6.8 without changing any defaults.
The webserver seems to work okay, but the permissions on the htdocs directory are set to "Read only" for everyone other than system. So (a) I have to provide root password every time I copy in web content, and, more problematic, (b) NetBeans says it can't create a target directory, and doesn't even generate the index.php file in the source directory.
Do I just need to manually change permissions on the htdocs directory, or is there some more global XAMPP setting that should be changed? Running NetBeans as root seems a bit extreme.
Tried the above but the option to amend the permission was not available for the htdocs folder,
My solution was:
Open applications folder
Locate XAMPP folder
Right click, get info (as described above)
In pop-up window locate the 'sharing & permission' section
Click the 'locked' padlock symbol
Enter admin password
Change 'Everyone' permissions to read & write
In the get info window still, select the 'cog' icon' drop down option at the very bottom and select 'Apply to enclosed items' this will adjust the permission across all sub-folders as well.
Re-lock the padlock symbol
Close the 'Get Info' window.
Task complete, this will now allow you to populate sub-folders within the htdocs folder as needed to populate your website(s).
Make sure the XAMPP app is running then:
Under General Tab, in XAMPP app, click Open Terminal
A terminal will be launched with something like, root#debian:~#, on the terminal shell
on that terminal shell, type, chmod -R 0777 /opt/lampp/htdocs/ and enter
Exit, the terminal and you be good to go
For latest OSX versions,
Right click on the folder
Select Get Info
Expand the Sharing & Permission section
Unlock the folder by clicking lock icon on bottom right-corner
Now, select the user list and enable Read & Write privilege for the users
Click on the + icon to add username
Finally click settings icon and select Apply to enclosed items...
Following the instructions from this page,
Open the XAMPP control panel (cmd-space, then enter manager-osx.app).
Select Manage Servers tab -> select Apache Web Server -> click Configure.
Click Open Conf File. Provide credentials if asked.
Change
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
</IfModule>
to
<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User your_username
Group staff
</IfModule>
Save and close.
Using the XAMPP control panel, restart Apache.
Navigate to the document root of your server and make yourself the owner. The default is /Applications/XAMPP/xamppfiles/htdocs.
$ cd your_document_root
$ sudo chown -R your_username:staff .
Navigate to the xamppfiles directory and change the permission for logs and temp directory.
$ cd /Applications/XAMPP/xamppfiles
$ sudo chown -R your_username:staff logs
$ sudo chown -R your_username:staff temp
To be able to use phpmyadmin you have to change the permissions for config.inc.php.
$ cd /Applications/XAMPP/xamppfiles/phpmyadmin
$ sudo chown your_username:staff config.inc.php
For new XAMPP-VM for Mac OS X,
I change the ownership to daemon user and solve the problem.
For example,
$ chown -R daemon:daemon /opt/lampp/htdocs/hello-laravel/storage
If you use Mac OS X and XAMPP, let's assume that your folder with your site or API located in folder /Applications/XAMPP/xamppfiles/htdocs/API. Then you can grant access like this:
$ chmod 777 /Applications/XAMPP/xamppfiles/htdocs/API
And now open the page inside the folder:
http://localhost/API/index.php
Best solution for MAC OS Catalina Xampp
Open Finder
Press Cmd + shift + C
Macintosh HD => Users => copy {username}
Open /Applications/XAMPP/xamppfiles/etc/httpd.conf
Find User daemon edit daemon => {username}
Xampp Manage Server => Restart all
If you encounter problems in phpMyAdmin:
1. Browser (Chrome) restart
Goodluck
Go to htdocs folder, right click, get info, click to unlock the padlock icon, type your password, under sharing permission change the priviledge for everyone to read & write, on the cog wheel button next to the + and - icons, click and select apply to all enclosed items, click to accept security request, close get info. Now xampp can write and read your root folder.
Note:
If you copy a new folder into the htdocs after this, you need to repeat the process for that folder to have write permission.
When you move your files to the live server, you need to also chmod the appropriate files & folders on the server as well.
if you use one line folder or file
chmod 755 $(find /yourfolder -type d)
chmod 644 $(find /yourfolder -type f)
You can also simply change Apache Conf file to a different User Name and keep the group:
Apache Conf Applications/Xammp/etc/..
User 'User' = your user name in Mac os x.
Group daemon
sudo chown -R 'User':daemon ~/Sites/wordpress
sudo chmod -R g+w ~/Sites/wordpress
If you are running your page on the new XAMPP-VM version of MacOS you will have to set daemon as user and as group. Here you can find a great step-by-step illustration with screenshots from aXfon on how to do this.
As the htdocs folder under XAMPP-VM will be mounted as external volume, you'll have to do this as root of the mounted volume (root#debian). This can be achieved through the XAMPP-VM GUI:
See screenshot.
Once you are running as root of the mounted volume you can as described above change the file permission using:
chown -R daemon:daemon /opt/lampp/htdocs/FOLDER_OF_YOUR_PAGE
Source (w/ step-by-step illustration): aXfon
What worked for me was,
Open Terminal from the XAMPP app,
type in this,
chmod -R 0777 /opt/lampp/htdocs/
This Solved WordPress Filesystem Permissions in Bitnami XAMPP
By changing the file permissions in apps/wordpress folder mounted on MAC XAMPP-VM shown in the below screenshot.
sudo chown -R bitnami:daemon TARGET # [ Replace "TARGET" with your file/folder path ]
find TARGET -type d -print0 | xargs -0 chmod 775
find TARGET -type f -print0 | xargs -0 chmod 664
chmod 640 TARGET/wp-config.php
Source: bitnami
TARGET - Replace placeholder for your mounted filesystem wordpress path eg: '1.1.1.1/lampp/apps/wordpress'
Now you can edit your themes in VS-Code or any developer editor of your choice.
NOTE: This should be done only in your development environment.
Production build permissions are different & above doesn't apply
The above worked only for some directories but didn't for all root files. To change root files permissions, open Xampp app, within Xampp app click button 'open terminal'. once there do the following:
- go to root directory: cd ..
- got to directory where lamp is located: cd opt
- change lampp permissions: chown -R bitnami:root lampp
note: you can replace bitnami with your user, and root with your group.
as a second alternative that worked for some files:
go to your users folder in finder and find the .bitnami hidden folder, access xampp folder within it and change permissions:
/Users/username/.bitnami/stackman/machines/xampp
right click xampp folder under machines and change permissions to read & write
apply to enclosing folders with "cog icon"

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.

"Permission Denied" using cygwin in Windows

Background:
I am trying to write a [.bat] file so I can double click it and a bash script will get invoked. The bash script will start up a few windows GUI apps to monitor GPU/CPU temperatures. I just did a fresh install of cygwin v1.7.7-1 (downloaded today) and windows 7.
Code:
monitor-temps.bat:
C:\cygwin\bin\bash.exe ~/bin/monitor-temps.bash
pause
Code:
monitor-temps.bash:
#!/usr/bin/bash
"/cygdrive/c/Users/michael/Desktop/apps_and_drivers/GPU-Z.0.4.8.exe" &
Output:
After I double click the [.bat] file, I get a:
C:\Users\michael\Desktop>C:\cygwin\bin\bash.exe ~/bin/monitor-temps.bash
C:\Users\michael\Desktop>pause
Press any key to continue . . . /home/michael/bin/monitor-temps.bash: line 2: /cygdrive/c/Users/michael/Desktop/apps_and_drivers/GPU-Z.0.4.8.exe: Permission denied
I still get the same permissions error when I cd to the directory and manually execute the application.
Permissions:
From my experience with permission problems in Linux, everything looks good because I am the user I think I am, and the file has the expected permissions:
$ whoami
michael
$ ls -l GPU*
-rwx------+ 1 michael None 890720 2010-12-01 19:23 GPU-Z.0.4.8.exe
Question:
Does anyone know how to fix this? Am I missing something?
As a Developer, I use a shortcut to provide a command-line interface (CLI) that behaves similar to Linux, in my Windows environment, and ran into the same issue trying to untar a file.
The fix was to set the shortcut to "Run as Administrator".
If you are using this method to access your Cygwin environment, go to the properties of the shortcut, select the Advanced button to get the options to "Run as Administrator", check the box, click Ok. And off you go!!
You can also set your batch file to do this, by making a shortcut to it and doing the above.
Hope that helps!
I think you have to change the directory or file permission. If you want to change permission of a file or directory then you have to add full path with the code.
As if you want to change permission on cocos2d-x folder on C:\yourDirectory (I'm on Windows; on Mac it would be / instead of \) write the code on cygwin console:
chmod -R 775 /cygwindrive/c/yourDirectory
Note: If it's in C: drive you have to run it as administrator.
Check the mount table with cat /proc/mounts or mount and make sure that every mount point out of /, /usr/bin, /usr/lib has a noacl flag. If it's missing, correct /etc/fstab and reboot. (Rebooting synced up the noacl flag of the root mount point for me, and I do not know if the same can be achieved without rebooting).
Check for a NULL SID record and other strange records in the output of icacls against the file. They appear added on writing by the POSIX ACL translation layer in Cygwin (using "noacl" in /etc/fstab allows disabling that, but the damage will have already been done).
Resetting the Windows ACL just on the file may not be enough if the containing parents had the NULL SID record. One has to run
icacls c:\cygwin64 /reset /t /l /c
from Command Prompt to remove the extraneous records from the Windows ACL in each file and directory.
Update
Other commands reset the ownership, remove default ACLs and show ACLs of a known binary before and after the changes:
set croot=c:\cygwin64
icacls %croot%\bin\ls.exe
%croot%\bin\getfacl /bin/ls
takeown /F %croot% /R /D Y > nul
icacls %croot% /reset /T /C /L /Q
icacls %croot%\bin\ls.exe
%croot%\bin\getfacl /bin/setfacl
%croot%\bin\getfacl /bin/find
%croot%\bin\setfacl -bk /bin/find
%croot%\bin\find -P / -xdev -exec /bin/setfacl -bk "{}" +
icacls %croot%\bin\ls.exe
%croot%\bin\getfacl /bin/ls
The easiest way to fix this is:
Download Sysinternals ProcMon, start it and let it run for a while.
Exclude all processes that generate noise.
When the log becomes less busy, start your file access attempt.
Search the ProcMon log for "Access Denied" messages.
Investigate. Should be easy to fix.
-rwx------+ might be the problem. Some hidden acl may forbid x for you.
Reset your acl with setfacl then.
$ cat >/tmp/faclx <<EOF
user::rwx
group::r--
mask:rwx
other:r--
EOF
$ setfacl -f /tmp/faclx /cygdrive/c/Users/michael/Desktop/apps_and_drivers/GPU-Z.0.4.8.exe
Or you need elevated permissions:
$ cygstart --action=runas /cygdrive/c/Users/michael/Desktop/apps_and_drivers/GPU-Z.0.4.8.exe
I had this problem, and fixed it by cd to the directory which contains the box I just made (packaged, or, repackaged). Then vagrant box add <file.box> --name <name>. I think the PATHs fvck things up, and cause it to fail. Then double check with vagrant box list. Then I mkdir coolbox; cd coolbox. Then I just vagrant init <name> and it all comes up like magic.
git bash, run command like this: cmd "/C postgresql-10.5-2-windows-x64.exe --unattendedmodeui minimal --mode unattended --servicename 'postgreSQL'"
I had a similar issue around tee redirection:
"%CYGWIN_ROOT%\bin\bash.exe" -c "{ cd ""%PWD:\=/%""; CHERE_INVOKING=. ""%CYGWIN_ROOT:\=/%/bin/bash.exe"" -l -i; } 2>&1 | ""%CYGWIN_ROOT:\=/%/bin/tee.exe"" -a ""%PROJECT_LOG_FILE:\=/%"""
This kind of code is required if you want to run a bash shell with login in a specific directory (cd before call to login shell).
But in mine case it won't work, because of the error: tee: 'standard output': Permission denied
Update:
Found a fix here: https://sourceware.org/pipermail/cygwin/2020-December/247185.html
In Win7,
1) Start command prompt.
2) Run chcp 65001
3) Change the font of command prompt to raster font.
4) Run c:\cygwin\bin\printf "\xce\b1\n"
This causes the error:
/usr/bin/printf: write error
What weird is that if the font is other than raster font,
this error does not occur.
A raster font triggers the console write error (a permission denied in case of piping) under 65001 code page specifically in the Windows 7.
You can follow the instruction found in this link: https://cygwin.readthedocs.io/en/latest/install/#install-and-maintain-cygwin
and when it comes to give permissions to the folder on windows use the command:
chmod ugo+x /usr/local/bin/cyg-get
From the Cygwin Terminal , as in this example:
Open Cygwin64 Terminal, and run:
chmod -R 775 /usr/local/bin/
just change the mode of the scripts using chmod command to make it executable.
see man chmod for more details.

Resources