Using setgid

The setgid special permission is used to enable group inheritance from the parent directory. When setgid is set on a directory, then files created in that directory will inherit the group affiliation from the parent directory, instead of inheriting it from the user who creates the file. It is generally used on collaborative (shared) directories to automatically change a file from the default user private group to the shared group. 

The following command line is used to view the existing permission of a directory:

$ ls -ld mydir

The following example illustrates the usage of the chmod command to add the setgid permission to a directory:

$ chmod g+s mydir
or
$ chmod 2770 mydir
$ ls -ld mydir

Here is a table listing special permissions and their effect on files and directories:

Special permission

Numerically fourth-digit weightage

Effects on files

Effects on directories

setuid (u+s)

Setuid= 4

Files are executed as the user that owns the file, not the user running that file

No effect

setgid (g+s)

Setgid = 2

Files are executed as the group that owns the file

Enables group inheritance. Files created in the directory have their group owner set as the group owner of the directory

sticky bit (o+t)

Sticky bit = 1

No effect

Only the root or the owner of the files can delete the files from the directory with a sticky bit set

 

Extra care is to be taken when setting these special permissions, as incorrect setting (usage) of the setuid and setgid on binaries can lead to privilege escalation. Such scenarios can help an attacker gain access to the root account via a regular user account.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.108.11