How to Set Sticky Bit on Shared Directory in Ubuntu
Managing shared directories in Ubuntu requires specific permissions to prevent users from deleting each other’s files. This article provides a quick guide on enabling the sticky bit, a special permission bit that restricts file deletion to the file owner, root, or directory owner. You will learn the exact command to apply this setting and how to verify it is active on your system.
The Command to Change the Sticky Bit
To enable the sticky bit on a shared directory, use the
chmod command with the +t flag. This ensures
that within the specified folder, only the file owner, the directory
owner, or the root user can delete or rename files.
Run the following command in your terminal:
sudo chmod +t /path/to/shared/directoryAlternatively, you can use the octal mode representation. Adding a
1 before the standard permission numbers sets the sticky
bit. For a typical shared directory with full access for everyone,
use:
sudo chmod 1777 /path/to/shared/directoryVerifying the Sticky Bit
To confirm that the sticky bit has been applied successfully, list
the directory details using the ls command with the
-ld flags.
ls -ld /path/to/shared/directoryIn the output, look at the permission string. If the sticky bit is
set, the execute permission for others will appear as a lowercase
t. If the execute bit is not set for others, it will appear
as an uppercase T.
Removing the Sticky Bit
If you need to disable this feature later, use the -t
flag with the chmod command.
sudo chmod -t /path/to/shared/directoryThis reverts the directory permissions to standard behavior where users with write access can delete any file within the folder.