Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » Set Special File Permissions with SUID or GUID and Sticky Bit
  • windows 10 logo 100739284 large
    Application pool has been disabled or Changing identity user for IIS Application Pool (Event ID 5059) Web Server
  • Comprehensive guide on WSUS setup
    How to install WSUS on Windows Server 2022 Windows Server
  • hyper v 1
    How to fix unable to create a new VM on HyperV Virtualization
  • xxxxxx 1
    Active Directory Administrative Tools shortcut Windows Server
  • How to Decrypt Files and Folders Encrypted with EFS in Windows 10
    How to decrypt Files and Folders Encrypted with an Encryption File System (EFS) in Windows Windows
  • ios microsoft remote desktop app
    Prevent the Saving of RDP Credentials in Windows 10 Windows
  • Remove Bing Chat Button from Edge Sidebar
    How to Remove Bing Chat Button from Edge Sidebar Windows
  • Slide2 3
    Sudo Error on Ubuntu: Fixing ‘unknown uid 1000: Who are you?’ Linux

Set Special File Permissions with SUID or GUID and Sticky Bit

Posted on 28/11/202208/04/2025 Imoh Etuk By Imoh Etuk No Comments on Set Special File Permissions with SUID or GUID and Sticky Bit
SUID GUID Sticky Bit 1

In this article, we shall discuss how to Set Special File Permissions with SUID or GUID and Sticky Bit in Linus. Linux is a multi-user operating system that allows you to create multiple users and grant user-level access to all files and directories. Please see How to determine GPO from GUID or Name, how to “Fix You Might Not Have Permission to Use This Network Resource Error, and “Change your root password: Manage the root user on your macOS“.

Certain files and directories, such as the /tmp directory, can be accessed by all users on your system. The issue with such directories is that any user can modify or delete files created by other Linux users, either intentionally or unintentionally.

To avoid such problems, Linux supports special permissions such as SUID, GUID, and Sticky Bit. Sticky Bit allows only the owner or the root to modify/delete files.

You can also set permissions on executable files to allow the file being executed to be executed with the privileges of the owner or the group user.

Set Special File Permissions in Linux

In this write-up, you will learn about SUID, GUID, and Sticky Bit and they work. It is important to know that, in Linux, everything has an owner and is a file. The root user, who has exceptional permissions to run anything and everything, is known as the root.

Everyone else has very limited rights and access to certain files and directories. One needs to utilize the sudo command in order to work with elevated privileges. Giving out the root password to haphazard individuals whenever they need to perform tasks requiring greater privileges is not a good idea, though.

It is assumed that you have already familiarize yourself with the regular read-write and execute permissions in Linux as shown in the image below:

Permissions-in-Linux
Regular Permission in Linux

Apart from these regular permissions, there are a few special file permissions and not many Linux users are aware of it. This is where SUID, GUID, and Sticky Bit come into the picture. Now let’s look at each special permission one after the other.

Pleaase, see Linux Cheat Sheet: The Linux Command Line, how to Switch between Users in Linux, and how to Save Read-Only Files in VIM Editor in Linux/Unix-like OS

What is SUID?

SUID which stands for Set User Owner ID is an executable’s permission bit flag that enables an alternate user to run an executable with the same permissions as the file’s owner rather than the alternate user’s permissions. If the SUID bit on an executable file is set, the executable file will be executed with the same permissions as its owner.

For instance, if you look using the ls -l command at the binary executable file of the passwd command, it has the SUID bit set.

ls -l /usr/bin/passwd

See the screenshot below for more information.

SUID-set

From the screenshot above, it means any user running the passwd command will be running it with the same permission as the root. The SUID special file permission for executable files.

This enables other users to run the file with the effective permissions of the file owner. You will notice that instead of normal x which represents executable permissions, the SUID is represented with the letter “s” which indicates  special permission for the user.

The benefit is that the passwd command needs to edit files like /etc/passwd, /etc/shadow to change the password. These files are owned by root and can only be modified by root.

But with the help of setuid flag (SUID bit), a regular user will also be able to modify these files (that are owned by root) and change his/her password. This is the reason why you can use the passwd command to change your own password despite of the fact that the files are owned by root.

You can review the following posts to learn more about Linux commands: How to Rename or Move a File or Directory in Linux – Bash Terminal Command. Also, see Locate, Find, and Grep: How to search for files and patterns in Linux or Unix like OS,

Setting Special File Permissions with SUID bit

The chmod command in symboli mode can be used to set SUID bit. For example to set SUID bit, run:

chmod u+s <file_name>
Setting-SUID-with-Sudo-Permission
Setting SUID in a File

The letter small letter “s” indicate that the SUID has been set on the file.

How to remove SUID?

To remove SUID from a file, run:

chmod u-s <file_name>
Removing-SUID-1
Removing SUID from a file

Alternatively, you can use the numeric method with 0 instead of 4 with the permissions you want to set:

chmod 0766 <file_name>
Alternative-way-to-remove-SUID
Alternate way

Difference between small “s” and capital “S” as SUID bit

The meaning of SUID of allowing the execution of a file with the same permissions as its owner. If you set the SUID bit, it will show a capital S, not small s:

Setting-SUID-on-a-file
Wrong Way of Setting SUID

The capital S as SUID flag indicates that there is a problem that has to be investigated. There is no executable permission on the file, despite the fact that you want it to be executed with the same permissions as the owner. The owner cannot even execute the file, and if the file cannot be executed, you will not be granted permission. The entire purpose of setting the SUID bit is defeated by this.

What is SGID?

The sole difference between the SGID permission and the SUID permission is that when a script or command with the SGID permission is run, it behaves as though it is a member of the same group as the file.

It’s useful for managing directories. When SGID permission is granted to a directory, any files and subdirectories created inside of it will have the same group ownership as the directory’s primary directory (not the group ownership of the user that created the files and directories).

ls -ld /var/local

Open your terminal and check the permission on the file /var/local:

Check-SGID
Checking SGID on a Directory

The letter “s” appears in this folder, /var/local, where you would expect to see “x” or “-” for group rights.

How to set SGID?

You can set the SGID bit in symbolic mode like this:

chmod g+s <directory_name>
Setting-SGID-in-Directory
Setting SGID on a Directory

The numerical approach is an alternative. Simply add a fourth digit to the standard permissions. The octal number that SGID always uses is 2.

chmod 2775 <directory_name>

Removing SGID

Just use the -s instead of +s as shown below:

chmod g-s <directory_name>
Removing-SGID
Removing SGID

Removing SGID numerically is the same as removing SUID. Use the additional 0 before the permissions you want to set:

chmod 0755 folder1
Removing-SGID-Numerically
Removing SGID using Numerical Method

Note: If a lowercase letter “l” appears in the group’s execute field. It indicates that the setgid bit is on, and the execute bit for the group is off or denied.

What is a Sticky Bit?

The sticky bit works on the directory. When a directory’s sticky bit is enabled. Only the root user or the file owners can delete or rename any of the files in the directory.

image-60

This is frequently used in the /tmp directory, which serves as the temporary files’ trash bin.

Checking-Sticky-Bit
Checking Sticky Bit Permission

As you can see, the folder /tmp, has the letter t in the same place we expect to see x or – for others’ permissions. This means that a user (except root) cannot delete the temporary files created by other users in the /tmp directory.

How to set the sticky bit?

As usual, the sticky bit in Linux can be set using both symbolic and numeric modes.

Adding-Removing-sticky-bit
Adding-Removing Sticky Bit

The numeric way is to add a fourth digit to the normal permissions As shown in the screenshot above. The octal number used for the sticky bit is always 1. Removing Stick Bit is also described in the image above. It can be achieved symbolically by adding the -t flag instead of +t.

You can also remove Sticky Bit using the numerical mode as shown below:

chmod 0775 <directory_name>
Using-Numerical-Mode-to-remove-sticky-bit
Using Numerical Mode to Remove Sticky Bit

From what we have discussed so in the post. You could see those specific permissions are easy to understand while working on your favorite Linux Disto. But they should still be utilized with extreme caution.

I hope you found this article useful on how to set Special File Permissions with SUID or GUID and Sticky Bit in Linux. In case you have any questions do not hesitate to ask in the comment section.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Linux

Post navigation

Previous Post: How to enable or fix the missing fast startup option on Windows 11
Next Post: Change Account Lockout Threshold for Local Accounts in Windows: The reference account is locked

Related Posts

  • squid proxy feature
    How to Set Up and Configure a Squid Proxy Server Linux
  • Screenshot 2022 04 13 at 21.38.35
    Check Weather Conditions via Command Line on Windows, macOS, Linux and Web Linux
  • FEATURE IMAGE BASE URL 1
    How to solve cannot find a valid base URL for repo: base/7/x86_64 Linux
  • 1 pUEZd8z  1p 7ICIO1NZFA
    The package python-virtualenv has no installation candidate error Linux
  • ClamAV
    How to install and manage ClamAV and ClamTK on Ubuntu Linux Anti-Virus Solution
  • sdf
    Creating an offline local repository in Linux Linux

More Related Articles

squid proxy feature How to Set Up and Configure a Squid Proxy Server Linux
Screenshot 2022 04 13 at 21.38.35 Check Weather Conditions via Command Line on Windows, macOS, Linux and Web Linux
FEATURE IMAGE BASE URL 1 How to solve cannot find a valid base URL for repo: base/7/x86_64 Linux
1 pUEZd8z  1p 7ICIO1NZFA The package python-virtualenv has no installation candidate error Linux
ClamAV How to install and manage ClamAV and ClamTK on Ubuntu Linux Anti-Virus Solution
sdf Creating an offline local repository in Linux Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • windows 10 logo 100739284 large
    Application pool has been disabled or Changing identity user for IIS Application Pool (Event ID 5059) Web Server
  • Comprehensive guide on WSUS setup
    How to install WSUS on Windows Server 2022 Windows Server
  • hyper v 1
    How to fix unable to create a new VM on HyperV Virtualization
  • xxxxxx 1
    Active Directory Administrative Tools shortcut Windows Server
  • How to Decrypt Files and Folders Encrypted with EFS in Windows 10
    How to decrypt Files and Folders Encrypted with an Encryption File System (EFS) in Windows Windows
  • ios microsoft remote desktop app
    Prevent the Saving of RDP Credentials in Windows 10 Windows
  • Remove Bing Chat Button from Edge Sidebar
    How to Remove Bing Chat Button from Edge Sidebar Windows
  • Slide2 3
    Sudo Error on Ubuntu: Fixing ‘unknown uid 1000: Who are you?’ Linux

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,832 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.