“许可被拒绝”在 Windows 中使用 cygwin
背景: 我正在尝试编写一个 [.bat] 文件,这样我就可以双击它并调用 bash 脚本。 bash 脚本将启动一些 Windows GUI 应用程序来监视 GPU/CPU 温度。我刚刚全新安装了 cygwin v1.7.7-1(今天下载)和 Windows 7。
代码: Monitor-temps.bat:
C:\cygwin\bin\bash.exe ~/bin/monitor-temps.bash
pause
代码: Monitor-temps.bash:
#!/usr/bin/bash
"/cygdrive/c/Users/michael/Desktop/apps_and_drivers/GPU-Z.0.4.8.exe" &
输出: 双击 [.bat] 文件后,出现:
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
当我 cd 到该目录并手动执行应用程序时,仍然出现相同的权限错误。
权限: 根据我在 Linux 中处理权限问题的经验,一切看起来都很好,因为我就是我认为的用户,并且文件具有预期的权限:
$ whoami
michael
$ ls -l GPU*
-rwx------+ 1 michael None 890720 2010-12-01 19:23 GPU-Z.0.4.8.exe
问题: 有谁知道如何解决这个问题?我错过了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
作为一名开发人员,我在 Windows 环境中使用快捷方式提供行为类似于 Linux 的命令行界面 (CLI),并在尝试解压文件时遇到了相同的问题。
修复方法是将快捷方式设置为“以管理员身份运行”。
如果您使用此方法访问 Cygwin 环境,请转到快捷方式的属性,选择“高级”按钮以获取“以管理员身份运行”选项,选中该框,然后单击“确定”。然后你就走吧!
您还可以通过创建批处理文件的快捷方式并执行上述操作来设置批处理文件来执行此操作。
希望有帮助!
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!
我认为你必须更改目录或文件权限。如果您想更改文件或目录的权限,则必须使用代码添加完整路径。
就好像您想更改 C:\yourDirectory 上的 cocos2d-x 文件夹的权限(我在 Windows 上;在 Mac 上,它是
/
而不是\
),编写以下内容cygwin 控制台上的代码:注意:如果它位于 C: 驱动器中,则必须以管理员身份运行它。
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:Note: If it's in C: drive you have to run it as administrator.
使用
cat /proc/mounts
或mount
检查挂载表,并确保每个挂载点都在/
、之外/usr/bin
、/usr/lib
有一个noacl
标志。如果丢失,请更正/etc/fstab
并重新启动。 (重新启动为我同步了根挂载点的noacl
标志,我不知道是否可以在不重新启动的情况下实现相同的效果)。在 icacls 的文件输出中检查 NULL SID 记录和其他奇怪的记录。它们似乎是由 Cygwin 中的 POSIX ACL 转换层写入时添加的(在 /etc/fstab 中使用“noacl”允许禁用它,但损坏已经造成)。
如果包含的父项具有 NULL SID 记录,仅在文件上重置 Windows ACL 可能还不够。一个人必须跑
从命令提示符中删除每个文件和目录中 Windows ACL 中的无关记录。
更新
其他命令重置所有权、删除默认 ACL 并显示更改前后已知二进制文件的 ACL:
Check the mount table with
cat /proc/mounts
ormount
and make sure that every mount point out of/
,/usr/bin
,/usr/lib
has anoacl
flag. If it's missing, correct/etc/fstab
and reboot. (Rebooting synced up thenoacl
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
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:
解决此问题的最简单方法是:
The easiest way to fix this is:
-rwx------+ 可能是问题所在。某些隐藏的 acl 可能会禁止您使用 x。
然后用 setfacl 重置你的 acl。
或者您需要提升权限:
-rwx------+ might be the problem. Some hidden acl may forbid x for you.
Reset your acl with setfacl then.
Or you need elevated permissions:
我遇到了这个问题,并通过 cd 到包含我刚刚制作的盒子(打包或重新打包)的目录来修复它。然后
vagrant box 添加; --name <名称>
。我认为 PATHs fvck 出了问题,并导致它失败。然后仔细检查vagrant box list
。然后我 mkdir Coolbox; cd 酷盒。然后我只需vagrant init
,一切就像魔术一样出现。I had this problem, and fixed it by
cd
to the directory which contains the box I just made (packaged, or, repackaged). Thenvagrant box add <file.box> --name <name>
. I think the PATHs fvck things up, and cause it to fail. Then double check withvagrant box list
. Then Imkdir coolbox; cd coolbox
. Then I justvagrant init <name>
and it all comes up like magic.git bash,运行如下命令:
cmd "/C postgresql-10.5-2-windows-x64.exe --unattendedmodeuiimal --mode unattended --servicename 'postgreSQL'"
git bash, run command like this:
cmd "/C postgresql-10.5-2-windows-x64.exe --unattendedmodeui minimal --mode unattended --servicename 'postgreSQL'"
我在 tee 重定向方面遇到了类似的问题:
如果您想在特定目录中运行登录的 bash shell(在调用登录 shell 之前使用
cd
),则需要这种代码。但在我的情况下,它不会工作,因为错误:
tee:'标准输出':权限被拒绝
更新:
在这里找到修复:https://sourceware.org/pipermail/cygwin/2020-December/247185.html
光栅字体会在 65001 代码页(特别是在 Windows 7 中)下触发控制台写入错误(在管道情况下,
权限被拒绝
)。I had a similar issue around tee redirection:
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
A raster font triggers the console write error (a
permission denied
in case of piping) under 65001 code page specifically in the Windows 7.您可以按照此链接中的说明进行操作:https:// /cygwin.readthedocs.io/en/latest/install/#install-and-maintain-cygwin
当需要为 Windows 上的文件夹授予权限时,请使用以下命令:
chmod ugo+x /usr/local/bin/cyg-get
从 Cygwin 终端 ,如本例所示:
打开 Cygwin64 终端,然后运行:
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 命令更改脚本的模式即可使其可执行。
请参阅 man chmod 了解更多详细信息。
just change the mode of the scripts using chmod command to make it executable.
see man chmod for more details.