Go fork/exec permission denied error

后端 未结 5 1742
终归单人心
终归单人心 2021-01-04 10:09

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 foll

相关标签:
5条回答
  • 2021-01-04 10:37

    Consider trying:

    sudo mount -o remount exec /tmp
    
    0 讨论(0)
  • 2021-01-04 10:41

    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.

    0 讨论(0)
  • 2021-01-04 10:54

    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

    0 讨论(0)
  • 2021-01-04 10:55

    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.

    0 讨论(0)
  • 2021-01-04 11:00

    To fix this issue on my Chromebook I just remounted ~/tmp as executable. There may be security implications in doing this, but since go run works on other platforms I figure maybe it's not that bad (especially on a local dev machine):

    sudo mount -i -o remount,exec /tmp/
    

    I added this to my .bash_profile script.

    0 讨论(0)
提交回复
热议问题