Explain sticky bit.

QuestionsQuestions4 SkillsProBasic Files OperationsSep, 04 2025
0140

Understanding the Sticky Bit in Linux

The sticky bit is a special permission that can be set on directories in Linux. It plays a crucial role in enhancing security, especially in shared environments where multiple users have access to the same directory.

What Does the Sticky Bit Do?

When the sticky bit is set on a directory, it restricts file deletion within that directory. Specifically, it allows only the owner of a file (or the root user) to delete or rename the files they own, regardless of the directory's write permissions.

Use Case

The sticky bit is commonly used on directories like /tmp, where many users can create temporary files. By setting the sticky bit, users cannot delete or rename files created by others, which helps prevent accidental or malicious file deletions.

How to Set the Sticky Bit

You can set the sticky bit using the chmod command with the +t option. Here’s how to do it:

chmod +t directory_name

For example, to set the sticky bit on the /tmp directory:

chmod +t /tmp

Viewing the Sticky Bit

When you list the permissions of a directory with the ls -l command, the sticky bit is indicated by a t in the execute position for others. For example:

ls -ld /tmp

Output might look like this:

drwxrwxrwt 10 root root 4096 Oct 25 12:34 /tmp

In this output:

  • The t at the end of drwxrwxrwt indicates that the sticky bit is set.

Summary

The sticky bit is an important feature for managing file permissions in shared directories. It ensures that users can only delete or rename their own files, enhancing security and preventing conflicts in multi-user environments.

If you have any more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!