Ubuntu says "bash: ./program Permission denied"

BashShellSh

Bash Problem Overview


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?

Bash Solutions


Solution 1 - Bash

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.

Solution 2 - Bash

Try this:

sudo chmod +x program_name
./program_name 

Solution 3 - Bash

Sounds like you don't have the execute flag set on the file permissions, try:

chmod u+x program_name

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKianView Question on Stackoverflow
Solution 1 - BashEric PostpischilView Answer on Stackoverflow
Solution 2 - BashVitor VillarView Answer on Stackoverflow
Solution 3 - BashSam RobertsView Answer on Stackoverflow