Software⏱️ 3 min read📅 2026-06-03

How to Fix: Running my program says "bash: ./program Permission denied"

Permission denied error when running a compiled C++ program on a different computer.

Quick Answer: Check if the executable file has execute permissions, and ensure that the user running the command on Computer 2 has the same privileges as on Computer 1.

The error 'bash: ./program_name: permission denied' occurs when the program you are trying to run does not have the necessary permissions to execute. This issue primarily affects users who try to run compiled C++ programs on a different system or device than where they were originally compiled.

This error can be frustrating because it prevents you from running your program, and you may spend time debugging without realizing the root cause of the problem. However, by following these steps, you should be able to resolve the issue and successfully run your C++ program.

⚠️ Common Causes

  • The primary reason for this error is that the compiled program has different ownership and permissions on computer 2 compared to computer 1 where it was originally compiled. This can happen when a file is copied or moved between systems without changing its permissions.
  • An alternative reason could be that the C++ compiler used on computer 1 and computer 2 have different settings or configurations, leading to differences in the generated executable files.

🛠️ Step-by-Step Verified Fixes

Change File Permissions

  1. Step 1: Step 1: Open a terminal on computer 2 and navigate to the directory where your program is located using the 'cd' command. For example, if your program is named 'program_name', you can use 'cd /path/to/program_name'.
  2. Step 2: Step 2: Use the 'chmod' command to change the file permissions of your program. You can specify the desired permissions by adding a number in front of the permission symbol (e.g., 'chmod u+x program_name'). For example, to make the program executable, you can use 'chmod u+x program_name'.
  3. Step 3: Step 3: Verify that the file permissions have been changed successfully by running your program again using './program_name'. If the error persists, you may need to adjust the permissions further or try a different method.

Recompile with the Same Compiler and Settings

  1. Step 1: Step 1: Compile your C++ program on computer 2 using the same compiler and settings that were used on computer 1. This may involve reinstalling the compiler, adjusting compiler flags, or changing other configuration options.
  2. Step 2: Step 2: Run the compiled program on computer 2 to verify that it executes successfully without any permission errors.

🎯 Final Words

By following these steps, you should be able to resolve the 'bash: ./program_name: permission denied' error and run your C++ program successfully on both computer 1 and computer 2. Remember to always check file permissions and compiler settings when transferring programs between systems to avoid this issue in the future.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions