NB: This tutorial has worked on Centos 6,7,8 and 9
SetGID allows a program to inherit the group ownership of the directory or file, rather than the group ownership of the user who runs the program.
Special Permission | Letter Representation | Numerical (Octal) Representation | Types of files it works on |
---|---|---|---|
setgid | s | 2 | executable files and folders |
We can enable the setgid as shown in the screenshot. The command “chmod g+s example.txt” enables the setgid on the example.txt file. When we do a long listing, we see that the group section of the file permissions have a letter “S” where the execute permission is normally placed. This means that the setgid is enabled.
We can then remove the setgid by using “g-s” on the file or folder. In this case I ran “chmod g-s example.txt” to remove it from the “example.txt file. When we do the listing using “ls -l”, we see that the letter “s” is removed meaning that the setgid is disabled on the file.
We can also enable the setgid using octal(numbers). We use number “2” in front of the standard permissions as seen in the figure. Here I ran “chmod 2644 example.txt” to enable the setgid on the example.txt file. When we do a long listing with “ls –l”, we see that the letter “S” is on the group section of the permissions which shows that the setgid is enabled on the file or directory.
We can then remove the setgid by using zero “0” in front of the standard permisions. In this case I ran “chmod 0644 example.txt” to remove the setgid from the “example.txt file. When we do the listing using “ls -l”, we see that the letter “s” is removed, meaning that the setgid is disabled on the file.