goubuntu-18.04setuid

setuid: operation not supported


package main

import (
        "log"
        "syscall"
)

func main() {
        setuidErr := syscall.Setuid(0)
        if setuidErr != nil {
                log.Fatal(setuidErr)
        }
}

When I run above code, I get the following error:

operation not supported
exit status 1

go version: 1.15.5

Can anyone help me?


Solution

  • Here is a quote from the official documentation

    On Linux Setuid and Setgid only affects the current thread, not the process. This does not match what most callers expect so we must return an error here rather than letting the caller think that the call succeeded.

    A possible solution is in this commit