Skip to main content
Engineering LibreTexts

03-C.4.1: Special Permission Types - The setgid Bit

  • Page ID
    26826
  • The setgid Bit

    The setgid affects both files as well as directories. When used on a file, it executes with the privileges of the group of the user who owns it instead of executing with those of the group of the user who executed it.

    When the bit is set for a directory, the set of files in that directory will have the same group as the group of the parent directory, and not that of the user who created those files. This is used for file sharing since they can now be modified by all the users who are part of the group of the parent directory.

    To locate the setgid bit, look for an ‘s’ in the group section of the file permissions. We show a find command that will search your entire system looking for setgid files, and the output for the wall command.

    pbmac@pbmac-server $ sudo find / -perm -2000
    
    -rwxr-sr-x 1 root tty 30800 Jan  8 10:31 /usr/bin/wall
    

    To set the setgid bit, use the following command - where filesname is the name of the file that you desire to set or remove the setgid bit:

    pbmac@pbmac-server $ chmod g+s filename
    

    To remove the setgid bit, use the following command:

    pbmac@pbmac-server $ chmod g-s filename
    

    Security Risks

    The setuid bit is indeed quite useful in various applications, however, the executable programs supporting this feature should be carefully designed so as to not compromise on any security risks that follow, such as buffer overruns and path injection. If a vulnerable program runs with root privileges, the attacker could gain root access to the system through it. To dodge such possibilities, some operating systems ignore the setuid bit for executable shell scripts.

    Adapted from: "SetUID, SetGID, and Sticky Bits in Linux File Permissions" by Anannya Uberoi 1, Geeks for Geeks is licensed under CC BY-SA 4.0

    • Was this article helpful?