Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the problem analysis and solution of Go run permission denied?

Shulou Source: shulou.com Published: 2022-05-31 22:00:26 10月24日 Update

Go run permission denied problem analysis and solution is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

0x01 problem

Once a colleague reported that the following exception occurred when go run xx.go was executed in the environment.

Fork/exec / tmp/go-build104992250/b001/exe/h: permission denied

I was a little interested, so I checked it out. The process of checking is relatively simple. I hope it will be helpful.

0x02 analysis

This problem occurs because the executable generated by go in the / tmp directory does not have execute permissions and will report an error when Go goes to execute it. Why is there no executive authority? After consulting colleagues, confirm that the mount options for / tmp in the development environment are shown below.

Tmpfs on / run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=524288k)

One of the options is noexec. As described in mount's man page, this option can disable binary executable permissions, which will improve the security of the system. This option is also effective for executable scripts in scripting languages such as Shell and Python.

Noexec Do not permit direct execution of any binaries on the mounted filesystem.0x03 solution

Since this option is a security requirement, it cannot be modified. Change your mind, can you let Go go somewhere else? My gut tells me that there should be an environment variable that controls this behavior. It is a pity that it has not been found in China.

Since it is an environment variable, go to the source directory to search. Through the GOROOT environment variable, it is confirmed that the environment variable in Go has the following characteristics. Env GOROOT=$WORK/parent/goroot has a prefix of env. Grep 'env'-rIn. | after grep-I tmp is executed, the environment variable GOTMPDIR is found. After trying it in the environment and GOTMPDIR=/root go run xxx.go, it runs successfully. Our problem's solved.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Environment variables problems permissions help analysis security colleagues directories scripts solutions clarity success regret binaries interests content prefixes reasons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Shulou Tech Info Shulou Technology NVidia