How to set the sticky bit?

0324

To set the sticky bit on a directory in Linux, you can use the chmod command. Here are the steps to do so:

1. Using Symbolic Mode

You can set the sticky bit using the +t option with the chmod command.

  • Syntax:

    chmod +t directory_name
  • Example:
    To set the sticky bit on a directory named shared_dir, you would run:

    chmod +t shared_dir

2. Using Numeric Mode

You can also set the sticky bit using numeric mode by adding a 1 at the beginning of the permission number.

  • Syntax:

    chmod 1777 directory_name
  • Example:
    To set the sticky bit along with full permissions (read, write, and execute) for user, group, and others on shared_dir, you would run:

    chmod 1777 shared_dir

3. Verifying the Sticky Bit

After setting the sticky bit, you can verify that it has been applied by using the ls -l command:

ls -ld directory_name
  • The output will show the permissions, and you should see a t in the execute position for others if the sticky bit is set.

  • Example Output:

    drwxrwxrwt  2 user group 4096 Jan 1 12:00 shared_dir
    • The t at the end of drwxrwxrwt indicates that the sticky bit is set.

Summary

To set the sticky bit on a directory, you can use either symbolic mode (chmod +t directory_name) or numeric mode (chmod 1777 directory_name). After setting it, verify the permissions to ensure the sticky bit is applied correctly.

0 Comments

no data
Be the first to share your comment!