155
./geany_run_script.sh: 5: ./geany_run_script.sh: ./Area_circumference: Permission denied

program exited with code: 126. This problem always occur when I try to execute my code. What might be the solution?

5
  • 2
    Permission denied error are occurs only if you don't have enough privilege to access that file. Jan 22, 2014 at 6:47
  • How can I change the permissions
    – khwilo
    Jan 22, 2014 at 7:01
  • Where do I do that please give me a shot example
    – khwilo
    Jan 22, 2014 at 8:01
  • When I do that it tells me this chmod: cannot access `geany_run_script.sh': No such file or directory. Should I run it from the terminal or what?
    – khwilo
    Jan 22, 2014 at 8:13
  • possible duplicate of How do I run .sh files in Terminal? Aug 6, 2014 at 5:23

5 Answers 5

249

Here's a link which explains about Changing file permission (and ownership)

If you want to skip these (for now of course), you can create a directory/folder in your user-home directory and work on your C programmes (or others) there.


You can open the terminal (press Ctrl + Alt + T) and cd to the target directory:

cd /path/to/target

To give the file "the_file_name" execute permission (if the file-system allows you with the RW rights):

chmod +x the_file_name
7
  • How can I change the permissions any examples
    – khwilo
    Jan 22, 2014 at 7:56
  • The problem how can I do that?I am a new Ubuntu user I recently switched from windows.
    – khwilo
    Jan 22, 2014 at 8:15
  • ..what's your working directory ie. what's the location of your source code file? ..do you have some experience with windows CLI?
    – rusty
    Jan 22, 2014 at 8:50
  • @wkhwilo-012, see if that helps and please don't hesitate to ask more..
    – rusty
    Jan 22, 2014 at 9:34
  • @wkhwilo-012, please copy your executable file Area_circumference and paste it (the file path will be pasted) to update your question's body...
    – rusty
    Jan 22, 2014 at 9:46
47

You need to give execute and read permissions. Follow this:

chmod u+r+x filename.sh

./filename.sh

When we make a new script file then by default it has read and write permission. But if we want to execute them, then we should give execute permission as shown above.

Execution bit alone is not enough for shell scripts, one must be able to read the file as well to execute it (contrary to binaries which only need the execute permission bit)

2
  • 2
    u (user) +rx (add read and execute permissions) Jan 9, 2020 at 10:06
  • 2
    Indeed, the second plus may be omitted - u+rx.
    – Artfaith
    May 24, 2022 at 0:56
4

Or you can excute it with your shell directly(or other shell versions), if you don't want to change the permission.

$ bash filename.sh
4
  • How does this work?
    – Rob Bell
    Oct 17, 2023 at 13:02
  • @RobBell bash a type of shell program used to interpret the bash script. Its synopsis is bash [options] [command_string | file], so it is possible we execute one command like this echo "echo hello world" | bash or bash script.sh, because we don't excute script with ./ so it is even no need to add #!/bin/bash(specify the interpreter) in the script . (more specifically, script.sh is just a file to be read by the interpreter bash in the command string bash script.sh)
    – Yan
    Oct 19, 2023 at 9:31
  • what I meant is how does this circumvent the security constraints?
    – Rob Bell
    Oct 25, 2023 at 10:14
  • 1
    @RobBell I am not sure if I could convince you with the following explanation. I don't think it is a security violation, although the script even can modify itself's provilege in its contents. When we execute a readable script like this, it just like executing its contents one by one in the terminal.
    – Yan
    Oct 30, 2023 at 2:33
2

Open your terminal application by pressing CTRL + ALT + T or with the apposite shortcut on the graphical enviroment (like Terminal or xTerm).
In the uniform window which appears on the screen you'll see a blinking character, it's the terminal cursor: simply click on the window and write to enter text (typically commands) and press ENTER to confirm the input.
Before the cursor there is always listed your current position on the file system from the root directory ("/") and your home (where your personal files are) is called "~".
To change directory/folder use cd EXISTENTFOLDER (replace EXISTENTFOLDER with the folder name); if you feel lost, simply type cd to return to your home directory in a blink!
Now let's solve your problem:

  1. Use the cd command to find the directory with your source code. Use TAB to help you. If you execute ls -lh, you'll see a list of possible paths to follow and files to execute.

  2. When you've find the blocked file execute chmod +x FILENAME (replace FILENAME with the name of your source code file).

  3. If you have multiple blocked files execute chmod +x * to unlock all files in the current directory. Never chmod +x dangerous or insecure files.

  4. Execute ./FILENAME YOUREVENTUALARGUMENTS to execute your executable file.

  5. Remember that if your compiled program tries to read/write outside your home directory you'll need to execute it as root by using sudo ./FILENAME YOUREVENTUALARGUMENTS.

If you want to have a manual for a command execute man COMMAND (replace COMMAND with the exact command name, Linux is case sensitive).

Some shells have an Open terminal here command to simplify your life, search for it in the future and remember that the command shell can be your best friend, if you use it well. :-D

It's all. If you need more help comment under here.
If I'm helping you press the UP arrow on the left; if you solve mark this answer as best answer.

Have a nice experience on Linux & Ubuntu.

1
  • Thanks a lot. Now I can work under the home directory. The operation you asked me earlier cannot be permitted. It says I have no permission but thanks anyway for the suggestion.
    – khwilo
    Jan 22, 2014 at 13:41
1

For the rest of us where the issue isn't caused by the execute bit not being set, @Avinash-Raj put it best:

Permission denied error are occurs only if you don't have enough privilege to access that file.

In my case, it was root lacking permission to access a fuse-based mount or mounted fs is set to noexec.. It really does boil down to whoever the script is run under lacking the necessary permissions to access or run the script.

To confirm that, use findmnt --target <filepath>

TARGET SOURCE FSTYPE OPTIONS
/tmp   tmpfs  tmpfs  rw,nosuid,nodev,noexec,size=1024k,inode64
                                    #^^^^^^         

I'm leaving this obvious/trivial answer here for my fellow fuse users to whom google will absolutely refuse to suggest any solution other than setting the execute bit.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .