Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu says "bash: ./program Permission denied" [closed]

Tags:

bash

shell

sh

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.

However, when I try to do this on computer 2, it says: bash: ./program_name: permission denied

What's wrong and what can I do about it?

like image 357
Kian Avatar asked Sep 23 '13 13:09

Kian


People also ask

How do I fix bash Permission denied in Ubuntu?

Solution to fix the bash: ./program_name: permission denied error. chmod u+x program_name– In this line, the chmod command will change the access mode to execute, denoted by x. only the file's owner will have the permission to execute the file.

How do I fix bash Permission denied in Linux?

To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.

How do I give bash script permission?

We can provide the executable permission by using the below command, chmod +x filename.sh. chmod (Change Mode) - Using chmod we can change the access permissions to file system objects. +x - It makes the file executable.

Why do I get permission denied in Terminal Ubuntu?

This error occurs when the user does not have the privileges to make edits to a file. Root has access to all files and folders and can make any edits. Other users, however, may not be allowed to make such edits. Remember that only root or users with Sudo privileges can change permissions for files and folders.


1 Answers

chmod u+x program_name. Then execute it.

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.

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.

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.

like image 83
Eric Postpischil Avatar answered Sep 27 '22 19:09

Eric Postpischil