Setuid/Setgid Demonstrator

<p>A Linux tool to visualize and understand setuid and setgid bits and their effect on file and directory permissions.</p>

S/GSetuid/Setgid Demonstrator

Read
Write
Execute
Owner
Group
Others
Current Permissions
777
rwxrwxrwx
Command: chmod

What are setuid and setgid?

setuid and setgid are special permission bits in Unix/Linux systems. When set on an executable file, setuid allows the file to run with the permissions of the file's owner, and setgid allows it to run with the permissions of the file's group. When set on a directory, setgid causes new files and subdirectories to inherit the group of the directory.

How to Recognize setuid/setgid

In a directory listing (ls -l), setuid and setgid appear as s or S in the execute position for owner and group:

  • s: Execute and setuid/setgid are set (e.g., -rwsr-xr-x or -rwxr-sr-x)
  • S: setuid/setgid is set, but execute is not (e.g., -rwSr-xr-x or -rwxr-Sr-x)

Setting setuid/setgid

To set setuid on a file:

chmod u+s /path/to/file

To set setgid on a file or directory:

chmod g+s /path/to/file_or_dir

Or numerically (the leading 4 sets setuid, 2 sets setgid):

chmod 4755 /path/to/file (setuid)
chmod 2755 /path/to/dir (setgid)

Where are setuid/setgid Used?

  • setuid is commonly used for programs that need root privileges, like passwd.
  • setgid is often used on directories for collaborative group access.

Stay Updated with Linux Tips

Get weekly tutorials, command references, and new tool announcements delivered straight to your inbox.