Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Use Sticky Bit to Manage Files on Shared Folders in Linux

Learn how to use sticky bit to manage files on shared folders in linux with clear steps, practical context, and useful troubleshooting guidance.

Table of Contents

This updated guide examines How to Use Sticky Bit to Manage Files on Shared Folders in Linux and organizes the essential facts, background, and practical takeaways in clear American English.

In this article, TipsMake.com discusses how you can use sticky bits to fine-tune file access on shared folders.

For illustrative purposes, the article has a system with 3 users - john1, john2 and john3 , all of which are members of a common group.

Suppose 'john1' creates a new directory named 'shared-dir' , which is shared among all johns users .

With thelscommand, we can view the permissions for 'shared-dir' , which is understood as follows: Only 'john1' can read the content as well as write to the directory. Because we are working with a shared folder, the goal is to make all users of the group write to 'shared-dir'.

To do so, we will modify the permissions using thechmodcommand. We will add write permissions for all johns users, as shown below.

How to Use Sticky Bit to Manage Files on Shared Folders in Linux — contextual image 1
Write permissions for all users of the johns group

We can see updated permissions for 'shared-dir' as shown below. The yellow underlined section indicates that the johns group has been granted write permissions.

Add files to the shared folder

Now, john1 adds two files ( j1_file1.txt and j1_file2.txt ) to 'shared-dir'.

For ease of understanding, the first two characters of the file name are synonymous with the username.

Similarly, john2 can also be written to the 'shared-dir' directory.

There are currently 4 files in 'shared-dir'.

How to Use Sticky Bit to Manage Files on Shared Folders in Linux — contextual image 2
4 files in 'shared-dir'

Is there a problem with the current settings?

File j1_file1.txt is created by john1 , the file owner. Now, john2 login and try to delete this file and he will be able to do so.

'john1' is the file owner, but 'john2' can delete it because the write permissions are granted to all members of the johns group .

This scenario is not ideal. We want all users to be able to write to the directory, but only the file owner can delete the file. How can this be achieved?

Introducing sticky bit

Sticky bits are a special permission, which is set on a write permissions folder for the whole group. This bit ensures that all members of the group can write to the directory, but only the file creator, or the file owner, can delete it.

Thechmodcommand with flag - t can be used to place sticky bits on a folder.

Updated rights can be seen below.

How to Use Sticky Bit to Manage Files on Shared Folders in Linux — contextual image 3
Permissions updated

Now, if 'john2' tries to delete the file 'j1_file2.txt' created by 'john1', that operation will not be allowed.

If you remove the executable rights from others, then the existence of sticky bits in the folder is indicated by a capital letter in the 'others' section of the permission string. The behavior of sticky bits on the folder remains the same.

How to Use Sticky Bit to Manage Files on Shared Folders in Linux — contextual image 4
The existence of sticky bits on folders is indicated by capital letters

Variant of chmod command

The digital form of thechmodcommand can also be used to place sticky bits on a folder.

chmod nxyz

Inside:

  • n = 1 : Refers to sticky bits. Other values of n refer to other special rights.
  • x : Rights to file owner.
  • y : Permission granted to the group that has access to the file.
  • z : Rights for others

To set sticky bit on 'shared-dir' , use the following command:

chmod 1755 shared-dir

The command produces the same result as using + t on existing default permissions.

The use of sticky bits is only suitable for folders and will not make sense when used for files.

FAQ

What is How to Use Sticky Bit to Manage Files on Shared Folders in Linux about?

It provides a structured overview of Linux, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.