“Permission Denied” using cygwin in Windows

筅森魡賤 提交于 2019-12-20 09:56:05

问题


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?


回答1:


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!




回答2:


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



回答3:


  • 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



回答4:


The easiest way to fix this is:

  1. Download Sysinternals ProcMon, start it and let it run for a while.
  2. Exclude all processes that generate noise.
  3. When the log becomes less busy, start your file access attempt.
  4. Search the ProcMon log for "Access Denied" messages.
  5. Investigate. Should be easy to fix.



回答5:


-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



回答6:


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.




回答7:


git bash, run command like this: cmd "/C postgresql-10.5-2-windows-x64.exe --unattendedmodeui minimal --mode unattended --servicename 'postgreSQL'"




回答8:


just change the mode of the scripts using chmod command to make it executable. see man chmod for more details.



来源:https://stackoverflow.com/questions/4479615/permission-denied-using-cygwin-in-windows

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