SGID:
Assigning SGID permission :
- Octal (2)
- Symbolic (g+s)
# chmod 2755 /myscript.sh
# ls -l
-rwxr-sr-x. 1 root root 0 Oct 16 11:33 /myscript.sh
Symbolic (g+s) :
# chmod g+s /myscript.sh
# ls -l
-rwxr-sr-x. 1 root root 0 Oct 16 11:33 /myscript.sh
Removing SGID permission
Octal (2) :
# chmod 0755 /myscript.sh
# ls -l
-rwxr-xr-x. 1 root root 0 Oct 16 11:33 /myscript.sh
Symbolic (g-s) :
# chmod g-s /myscript.sh
# ls -l
-rwxr-xr-x. 1 root root 0 Oct 16 11:33 /myscript.sh
Understanding difference between Capital (S) and small (s) in SGID
Now when you assign SGID permission you might sometimes see a Capital (S) instead of a small (s) in the group permission section. This does not makes much difference instead if gives you an additional information if that file is having group executable permission or not. If you get Capital S it means there is not executable permission and the same if you have small s it means the file is having group executable permission.
For example:
Before applying SGID without executable permission on user owner
# chmod 655 /myscript.sh
# ls -l
-rwxrw-rw-. 1 root root 0 Oct 16 11:35 /myscript.sh
After applying SGID without executable permission on user owner
# chmod 2655 /myscript.sh
# ls -l
-rwxrwSrw-. 1 root root 0 Oct 16 11:35 /myscript.sh
Before applying SGID with executable permission on user owner
# chmod 755 /myscript.sh
# ls -l
-rwxrwxrw-. 1 root root 0 Oct 16 11:36 /myscript.sh
After applying SGID with executable permission on user owner
# chmod 2755 /myscript.sh
# ls -l
-rwxrwsrw-. 1 root root 0 Oct 16 11:36 /myscript.sh
So I hope you have got my point of view and must have understood the difference between capital (S) and small (s)
Finding all the executable files with SGID
# find / -perm +2000
where +2000 is the ID we use for assigning permission in octal method.