"Permission Denied" using cygwin in Windows - windows-7

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.

Related

Batch script permissions issues

I have a batch script written to auto start and capture traffic on a server for me but for some reason when I run it wireshark tells me it doesn't have permission to the folder where the script is trying to save the file. I have tried multiple different folders on and off the server I have tried giving everyone including SYSTEM full access to the folder. I have tried remaking the folder. I have tried running under and not under admin credentials I have tried letting the system task run it. Always get a permissions issue.
The weirdest part is if I run wireshark manually and save the data manually it has no permissions issues. Just if I run the script is the problem. Although they're both run under the same admin account.
Here is the script in case you need to see the flags I used.
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp
pause
I did try to use a powershell script I had found online but it was pretty old and I couldn't get it to actually run. So any recommendations are welcome that include powershell or batch
C:\Temp isn't a file; it's a folder. Try specifying an actual filename, like this:
#echo off
cd C:\Program Files\Wireshark
Wireshark.exe -i 4 -k -a duration:10 -w C:\Temp\foo.pcapng
pause

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
.

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.

Terminal error: zsh: permission denied: ./startup.sh

I am running a command
./startup.sh nginx:start
and I am getting this error message
zsh: permission denied: ./startup.sh
why could this be happening?
Be sure to give it the execution permission.
cd ~/the/script/folder
chmod +x ./startup.sh
This will give exec permission to user, group and other, so beware of possible security issues. To restrict permission to a single access class, you can use:
chmod u+x ./startup.sh
This will grant exec permission only to user
For reference
Alternatively you can use bash:
bash startup.sh
Then you don't need execution permission.
In MacOS Catalina, Apple has replaced bash with zsh as default shell. This can mean, that they intend to remove bash in the future, so this might not be an option later, but with Catalina it still works.
Starting with macOS Catalina,
Your Mac uses zsh as the default login shell and interactive shell. You can make zsh the default in earlier versions of macOS as well.
How to change your default shell
Whether your user account is configured to use zsh (recommended), bash, or another shell, you can change the default shell from Users & Groups preferences or the command line.
From Users & Groups preferences
Choose Apple menu  > System Preferences, then click Users & Groups.
Click the lock , then enter your account name and password.
Control-click your user name in the list of users on the left, then choose Advanced Options.
Choose a shell from the ”Login shell” menu, then click OK to save the changes.
Follow link for more details - https://support.apple.com/en-in/HT208050
You need to grant execution permission to your file. Here's a way to do that.
Navigate to the folder that contains your file and run this command-
chmod 755 <filename>
The three digits of the number 755 represent permissions for the three types of users- Owner, Group, and Others.
So, 755 represents-
Digit (octal)
Binary
read
write
executable
for
7
111
1
1
1
owner
5
101
1
0
1
group
5
101
1
0
1
others
Thus this command gives all three permissions- read, write and executable to the owner, while only read and executable to group and others.
More details about permissions in MacOS/Linux are discussed here- https://askubuntu.com/questions/932713/what-is-the-difference-between-chmod-x-and-chmod-755
Another annoying error can be n typo in the sh script.
In the following example, the ZSH error message does confusing. ZSH does tell you zsh: permission denied: startup.sh. But you have access rights to your script. The issue is the invalid Shebang line in the script:
#!/usr/local/bin sh
The right Shebang line can be e.g.:
#!/usr/bin/env sh
Below worked for me but I don't know why.
My file permissions before making the below change were -rwxr-xr-x. Even though I had the execute permission but still i got the permission denied error.
I am using vs code editor. I executed chmod +x filename and the file permissions still remained the same. The only difference this time was that I was able to run the file. Something changed about the file but it's not visible. The reason why I say it's not visible is that in the source control tab of my editor, my new file and old file looked 100% the same. If I stash my changes and execute the file then again same error.
I don't know why and how it worked but it's worth a try.
I will be more than happy if someone can explain the reason to me why it did not work earlier as I had the same permissions? Also, what changed in my file which is not visible to me?
add sudo before command start, will save your time like
sudo anyTemninalCommand

Resources