Ubuntu 说“bash: ./program Permission denied”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18960689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu says "bash: ./program Permission denied"
提问by Kian
I am running Ubuntu on computer 1 and computer 2. I compiled a C++ program on computer 1, and I can execute it from the terminal using ./program_name
. It runs fine.
我在计算机 1 和计算机 2 上运行 Ubuntu。我在计算机 1 上编译了一个 C++ 程序,我可以使用./program_name
. 它运行良好。
However, when I try to do this on computer 2, it says: bash: ./program_name: permission denied
但是,当我尝试在计算机 2 上执行此操作时,它说: bash: ./program_name: permission denied
What's wrong and what can I do about it?
出了什么问题,我该怎么办?
回答by Eric Postpischil
chmod u+x program_name
. Then execute it.
chmod u+x program_name
. 然后执行它。
If that does not work, copy the program from the USB device to a native volume on the system. Then chmod u+x program_name
on the local copy and execute that.
如果这不起作用,请将程序从 USB 设备复制到系统上的本机卷。然后chmod u+x program_name
在本地副本上执行。
Unix and Unix-like systems generally will not execute a program unless it is marked with permission to execute. The way you copied the file from one system to another (or mounted an external volume) may have turned off execute permission (as a safety feature). The command chmod u+x name
adds permission for the user that owns the file to execute it.
Unix 和类 Unix 系统通常不会执行程序,除非它被标记为允许执行。您将文件从一个系统复制到另一个系统(或安装外部卷)的方式可能已关闭执行权限(作为一项安全功能)。该命令chmod u+x name
为拥有该文件的用户添加了执行它的权限。
That command only changes the permissions associated with the file; it does not change the security controls associated with the entire volume. If it is security controls on the volume that are interfering with execution (for example, a noexec
option may be specified for a volume in the Unix fstab
file, which says not to allow execute permission for files on the volume), then you can remount the volume with options to allow execution. However, copying the file to a local volume may be a quicker and easier solution.
该命令仅更改与文件关联的权限;它不会更改与整个卷关联的安全控制。如果是卷上的安全控制干扰了执行(例如,noexec
可以为 Unixfstab
文件中的卷指定一个选项,表示不允许对该卷上的文件具有执行权限),那么您可以重新挂载该卷带有允许执行的选项。但是,将文件复制到本地卷可能是更快、更简单的解决方案。
回答by Vitor Villar
Try this:
尝试这个:
sudo chmod +x program_name
./program_name
回答by Sam Roberts
Sounds like you don't have the execute flag set on the file permissions, try:
听起来您没有在文件权限上设置执行标志,请尝试:
chmod u+x program_name