Linux 101 : Impersonating a user - Set User ID "SUID", Set Group ID "SGID" -



In Linux we have some special permissions, like the Set User ID (SUID) and Set Group ID (SGID). 

The SUID, or the setuid allows a regular user to have the same permissions as the owner of a file or a program.

Some programs like the "passwd" command require privileged access that a regular user don't have.

For a regular user to be able to run a privileged command like "passwd", the "passwd" command is set up so that a regular user could run it as "root" who is the owner of the "passwd" program.

The SGID , or setgid allows a regular user to have the same permissions as the group that owns the file. 

The SGID could also be used with directories and their subdirectories.
The subdirectories inherit the SGID of their parent directory.

The files that live in these directories and their subdirectories inherit the directory's group ID.

These permissions are only applied to newly created files.

We can set both the SUID and SGID are using the "chmod" command.

We could check the setuid bit in the permissions of a file using the the below command:


Remark:

The SGID is represented by an "s" in the group "execute" permissions.

We could set the SUID permissions for a file using the below command:


We could set the SGID on a directory, using the below command:


To remove the GUID permission for example, we could use the below command: 


If for security reasons, we need to find all the files with SUID permissions, we could use the below command:


For the GUID files, we could use the below command:

Comments

Leave as a comment:

Archive