Compiled a binary from the golang source, but it won't execute. I tried downloading the binary, which also didn't work. Permissions all seem to be right. Running the file from go for some reason works.

Output of ~/go$ go run src/github.com/exercism/cli/exercism/main.go1:

   exercism - A command line tool to interact with http://exercism.io

   main [global options] command [command options] [arguments...]

Output of ~/go/bin$ ./exercism:

bash: ./exercism: Permission denied

Output of ~/go/bin$ ls -al:

total 9932
drwxr-xr-x 2 joshua joshua     4096 Apr 28 12:17 .
drwxr-xr-x 5 joshua joshua     4096 Apr 28 12:17 ..
-rwxr-xr-x 1 joshua joshua 10159320 Apr 28 12:17 exercism

Output of ~/go/bin$ strace ./exercism:

execve("./exercism", ["./exercism"], [/* 42 vars */]) = -1 EACCES (Permission denied)
write(2, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
exit_group(1)                           = ?
+++ exited with 1 +++
  • 1
    Do you have execute access to the directory containing the file? You need that to cd into the directory in the first place, but you would get this error if you're already int he directory and the executable bit is removed. – terdon Apr 28 '17 at 17:17
  • 1
    Also, please edit your question and explain the connection between src/github.com/exercism/cli/exercism/main.go1 and ./exercism. In the first case, exercism is a directory and in the second a file. – terdon Apr 28 '17 at 17:19
  • I do have access to the directory; the error was a drive mounted with noexec in effect. – Joshua Nelson Apr 28 '17 at 18:20

Check that noexec is not in effect on the mount point in question. Or choose a better place to launch your script from.

$ mount | grep noexec
[ snip ]
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime)
$ cat > /dev/shm/some_script
echo hi
$ chmod +x /dev/shm/some_script
$ /dev/shm/some_script
bash: /dev/shm/some_script: Permission denied
$ mv /dev/shm_script .
$ ./some_script

noexec exists specifically to prevent security issues that come from having world-writable places storing executable files; you might put a file there, but someone else might rewrite it before you execute it, and now you're not executing the code you thought you were.

  • Brilliant. You're absolutely correct - I have /home mounted as a seperate partition with noexec in effect. To fix this, I would edit /etc/fstab, correct? – Joshua Nelson Apr 28 '17 at 18:19
  • For a permanent fix, should be, yes. For a quick fix, you should also be able to run mount -o remount,exec /home as root. – Michael Mol Apr 28 '17 at 18:22
  • Update: I had in my fstab LABEL=home /home ext4 defaults,user 0 2 ; user implies no exec. I changed it to defaults and rebooted, now it works like a charm. Thanks for the help! – Joshua Nelson Apr 28 '17 at 18:29
  • 2
    Don't forget to Accept the answer. ;) – Michael Mol Apr 28 '17 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.