How to Add Sticky Bit in Linux

How to Add Sticky Bit in Linux

To how to add sticky bit in linux, use chmod +t on a directory, or the numeric mode chmod 1xxx if you prefer octal permissions. The sticky bit is commonly used on shared directories so users can create files without letting other users delete or rename them.

What the sticky bit does

The sticky bit is a special Linux permission that changes how deletions and renames work inside a directory. Without it, any user who has write access to a shared directory can usually delete or rename files in that directory, even if those files belong to someone else.

With the sticky bit set, only these users can remove or rename a file inside that directory:

  • The file owner
  • The directory owner
  • The root user

This is why the sticky bit is useful for shared spaces such as /tmp, where many users need to create files but should not interfere with each other’s data.

How to add the sticky bit in Linux

How to add the sticky bit in Linux

You can set the sticky bit with either symbolic or numeric syntax. Both do the same thing.

Using symbolic chmod

Run this command on the directory:

chmod +t /path/to/directory

Example:

chmod +t /shared

This adds the sticky bit without changing the existing read, write, or execute permissions.

Using numeric chmod

If you prefer octal notation, add 1 in front of the permission mode.

chmod 1777 /shared

In this example, 1777 means:

  • 1 = sticky bit
  • 7 = read, write, execute for the owner
  • 7 = read, write, execute for the group
  • 7 = read, write, execute for others

This is a common setting for public shared directories, where everyone can create files but deletion is restricted by ownership.

Set it only when needed

Adding the sticky bit is most useful on directories, not regular files. On Linux, the sticky bit on files is generally obsolete for everyday administration and is not commonly used the way it was on older Unix systems.

Check that the sticky bit is set

Check that the sticky bit is set

Use ls -ld to inspect the directory permissions:

ls -ld /shared

Typical output might look like this:

drwxrwxrwt 2 root root 4096 Nov  4 12:00 /shared

Look at the last character in the permission string:

  • t means the sticky bit is set and others have execute permission
  • T means the sticky bit is set but others do not have execute permission

For most shared directories, you will usually see a lowercase t.

Sticky bit vs setuid vs setgid

These three special permissions are easy to confuse, but they do different things.

Special bitApplies toWhat it does
Sticky bitDirectoriesRestricts deletion and renaming to file owners, directory owner, or root
setuidExecutable filesRuns the program with the file owner’s permissions
setgidExecutable files and directoriesRuns with group permissions on files, and can make new items inherit the directory group

A simple way to remember it is this: sticky bit controls deletion behavior in shared directories, setuid affects program execution, and setgid is usually about group inheritance and execution.

Common examples of using the sticky bit

/tmp

The /tmp directory is the best-known example. It is writable by many users, but the sticky bit prevents users from deleting each other’s temporary files.

Shared project folders

If several users work in a common directory, you may want them to create and edit files there while preventing accidental removal of someone else’s work.

Team drop zones

A shared upload or exchange folder can benefit from the sticky bit when multiple accounts need access but should not be able to clean up or rename files they do not own.

How to remove the sticky bit

If you no longer want the restriction, remove the sticky bit with either of these commands:

chmod -t /path/to/directory

or:

chmod 0777 /path/to/directory

Be careful with the second form, because it changes the full permission mode, not just the sticky bit. If you only want to remove the sticky bit, the symbolic form is safer.

Common mistakes and troubleshooting

Expecting the sticky bit to fix all permission problems

Expecting the sticky bit to fix all permission problems

The sticky bit only affects deletion and renaming in a directory. It does not grant write access, read access, or ownership changes. If users cannot create files, the problem is probably standard directory permissions, not the sticky bit.

Forgetting directory write permission

Users still need write and execute permission on the directory to create files there. The sticky bit does not replace normal access modes.

Applying it to the wrong path

Make sure you are setting the sticky bit on the directory that actually contains the shared files. If you set it on a parent directory by mistake, the behavior may not be what you expect.

Using the wrong mode for a shared directory

Using the wrong mode for a shared directory

Many shared directories use 1777, but not every environment should. A private team directory might need a more restrictive base mode, such as 1770 or 1750, depending on the group access you want.

Checking ownership as root

Remember that the directory owner and root can still remove files even when the sticky bit is set. That is normal behavior.

Quick examples you can reuse

# Add sticky bit to a shared folder
chmod +t /shared

# Set a common shared-directory permission model
chmod 1777 /shared

# Verify the result
ls -ld /shared

# Remove the sticky bit
chmod -t /shared

Frequently Asked Questions About how to add sticky bit in linux

What does the sticky bit do in Linux?

It prevents users from deleting or renaming files they do not own inside a directory, even if the directory is writable by many users.

How do I set the sticky bit on a directory?

Use chmod +t /path/to/directory or set the full mode with chmod 1777 /path/to/directory if that permission pattern fits your use case.

What is the chmod command for sticky bit?

The simplest command is chmod +t. The octal form is 1 placed before the normal permission digits, such as 1777.

How can I check if the sticky bit is set?

Run ls -ld /path/to/directory and look for a lowercase t or uppercase T in the others-execute position.

What is the difference between sticky bit and setgid?

Sticky bit controls who can delete files in a directory. Setgid mainly affects group behavior, and on directories it can help new files inherit the directory’s group.

Can I use the sticky bit on a file?

On modern Linux systems, the sticky bit is mainly useful on directories. For file permissions and execution behavior, setuid and setgid are the relevant special bits.

Conclusion

If you want to know how to add sticky bit in Linux, the practical answer is simple: use chmod +t or chmod 1777 on the directory, then confirm it with ls -ld. The sticky bit is most useful on shared directories where multiple users need to create files, but only the owner of a file should be able to remove it.

When you understand how it differs from setuid and setgid, it becomes much easier to choose the right permission model for a shared Linux folder.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *