These are special file permissions in Linux used to control access and enhance security.
SUID ( Set User Identification):
When a file with SUID bit is executed, it runs with file’s owner permission instead of user’s permission who executed it.
Example: Lets create a file name suidfile and lets check it’s permission.
Now if we want to add SUID bit with suidfile, it can be done with following:
chmod 4664 suidfile
So when we have checked the permissions of suidfile, there is capital S in Owner’s permission which means there is no executable permissions. In order to give it executeable permission, we will use following:
chmod 4764 suidfile
So, Now SUID and executable permissions are set to the suidfile and whenever you see that small “s" in permission, that means both execute bit and SUID bit are set.
Another way to do is with command “u+s” as shown below:
GUID (Group ID):
When we set GUID on a file, it allows the execution of file with group’s owner permission.
When it is set on directory, sub directories or new files will inherit it from parent director.
Example: Lets create a file name sguidfile and lets check it’s permission.
Now if we want to add GUID bit with sguidfile, it can be done with following:
In order to give it executeable permission, we will use following:
chmod 2674
You can see that small “s" in permission, that means both execute bit and GUID bit are set.
Another way to do this is with command “g+s” as shown below:
Sticky Bit
When sticky bit is set on a directory, only the file owner, directory owner, or superuser can delete or modify files within the directory.
Example: We can use “+t” to add sticky bit
Files in stickybitdir
can be deleted only by their owner or the superuser, even if others have write permissions.
Summary Table
Permission | Symbol | Function | Typical Usage |
SUID | s | Run file as the owner's privileges | passwd |
GUID | s | Run file with group privileges / Inherit group in dirs | Collaborative directories |
Sticky Bit | t | Restrict file deletion to owner | /tmp |