Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go fork/exec permission denied error

Tags:

go

I recently installed Go onto our server with CentOS 6.3. The install appears to have gone fine. However I made a test "hello world" script, and when I run I get the following output.

fork/exec /tmp/go-build967564990/command-line-arguments/_obj/a.out: permission denied

Now running go env or other go commands seem to work. At first I figured it was a permission issue, however running as root user I get the same thing. An

like image 772
user387049 Avatar asked Feb 18 '13 19:02

user387049


3 Answers

I encountered this issue today but the solutions above did not work. Mine was fixed by simply running:

$ export TMPDIR=~/tmp/

then I was able to get the script to run with:

$ go run hello.go
hello, world

The only downside is you have to run export TMPDIR every time you want to run an application.

Kudos to Adam Goforth

like image 197
Winter Avatar answered Oct 17 '22 22:10

Winter


Just guessing: Your nix perhaps disables for security reasons executing programs in /tmp. It might be configurable in CentOS, but I don't know that.

The alternative solution: It seems you're trying go run to execute a Go program (which is as script as C is a script). Try (assuming $GOPATH=~, the easy possibility) instead a normal build, i.e. instead of

me:~/src/foo$ go run main.go

try

me:~/src/foo$ go build # main.go should not be necessary here
me:~/src/foo$ ./foo

This approach will still use /tmp-whatever to create the binary, IIRC, but it will not attempt to execute it from there.

PS: Do not run these command as root. No need for that with correct setup.

like image 23
zzzz Avatar answered Oct 17 '22 23:10

zzzz


I am using Fedora 31 and got a similar error which brought me here. I could not run the Go debugger used by Jetbrains IntelliJ Ultimate/GoLand without fork/exec & permission denied error. The solution was this:

setsebool deny_ptrace 0

See https://fedoraproject.org/wiki/Features/SELinuxDenyPtrace for details.

like image 41
MonkeyMonkey Avatar answered Oct 18 '22 00:10

MonkeyMonkey