I am debugging a program and not quite sure why I can not drop privileges.

I have root permissions via sudo and I can call setgid/setuid, but the operation [is] is not supported.

Basic code to reproduce (golang):

package main

import (

func main() {
    if os.Getuid() != 0 {
        fmt.Println("run as root")

    uid, err := strconv.Atoi(os.Getenv("SUDO_UID"))
    check("", err)

    gid, err := strconv.Atoi(os.Getenv("SUDO_GID"))
    check("", err)

    fmt.Printf("uid: %d, gid: %d\n", uid, gid)

    check("gid", syscall.Setgid(gid))
    check("uid", syscall.Setuid(uid))

func check(message string, err error) {
    if err != nil {
        fmt.Printf("%s: %s\n", message, err)

Example output:

$ sudo ./drop-sudo 
uid: 1000, gid: 1000
gid: operation not supported

System info:

$ uname -a
Linux user2460234 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • 1
    I don't know if this ever got fixed, but Setuid/Setgid do not work properly with Go on Linux - github.com/golang/go/issues/1435 – Stephen Harris Sep 16 '18 at 22:49
  • comment out the Setuid line and see if Setgid works. – Rui F Ribeiro Sep 16 '18 at 22:52
  • @RuiFRibeiro that doesn't work either; they are in the right order (setgid before setuid). – user2460234 Sep 17 '18 at 0:32
  • Yeah, they are, it was just a test. – Rui F Ribeiro Sep 17 '18 at 0:45

Your programming language simply does not support such things.

It's complex to do this stuff on Linux, because of the architecture of Linux. The C libraries (e.g. GNU and musl) hide this complexity. It continues to be one of the known problems with threads on Linux.

The Go language does not replicate the mechanism of the C libraries. The current implementation of those functions is not a system call, and has not been since 2014.

Further reading

|improve this answer|||||
  • "The known problems with threads on Linux" still stands with current kernel(s)? – Paradox Jun 22 '19 at 19:42

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.