Skip to main content

What is Sticky Bit?

Sticky bit is an extra permission option for files and folders in linux. There are two main reasons for using sticky bit.
If it is applied to a regular file, the file’s image is kept in the memory so that if the file is required to be open it is loaded quickly.  The second reason for using sticky bit is about permissions. When sticky bit is set for a directory, owner of the directory will have permissions to delete all the files in that directory even if it has not ownership of a file.


An example makes it clear:
Say we have a directory named /sticky and two users named skipper and rico.
# whoami
root
# mkdir /sticky
# chown skipper:rico /sticky
# chmod 775 /sticky
#
# ls -la
drwxrwxr-x   2   skipper   rico   4096   Jul 17 16:59   sticky
# chmod +t /sticky
# ls -la
drwxrwxr-t   2   skipper   rico   4096   Jul 17 16:59   sticky
#
# su – skipper
$ cd /sticky
$ touch skipper.file
$ ls -la
drwxrwxr-t    2      skipper    rico   4096   Jul 17 17:08   .
drwxr-xr-x    39    root          root   4096  Jul 17 16:59    ..
-rw-rw-r–      1      skipper    skipper    0  Jul 17 17:08    skipper.file
$ exit
#
# su – rico
$ cd /sticky
$ touch rico.file
$ ls -la
drwxrwxr-t    2    skipper      rico   4096    Jul 17 17:13     .
drwxr-xr-x    39   root           root   4096    Jul 17 16:59   ..
-rw-rw-r–       1   rico            rico             0   Jul 17 17:13    rico.file
-rw-rw-r–       1   skipper      skipper    0   Jul 17 17:08   skipper.file

Now we can test permissions:
# whoami
root
# su – rico
$ cd /sticky
$ ls -la
drwxrwxr-t    2     skipper   rico    4096   Jul 17 17:13    .
drwxr-xr-x     39   root          root    4096  Jul 17 16:59    ..
-rw-rw-r–        1       rico          rico              0  Jul 17 17:13     rico.file
-rw-rw-r–        1       skipper  skipper      0 Jul 17 17:08    skipper.file
$ rm -f skipper.file
rm: cannot remove ‘skipper.file’: Operation not permitted
$ exit
#
# su – skipper
$ cd /sticky
$ ls -la
drwxrwxr-t    2      skipper   rico    4096    Jul 17 17:13    .
drwxr-xr-x     39   root           root    4096   Jul 17 16:59    ..
-rw-rw-r–        1       rico            rico              0  Jul 17 17:13     rico.file
-rw-rw-r–        1       skipper    skipper     0 Jul 17 17:08     skipper.file
$ rm -f rico.file
$ ls -la
drwxrwxr-t    2      skipper   rico     4096 Jul 17 17:25    .
drwxr-xr-x     39   root           root    4096 Jul 17 16:59    ..
-rw-rw-r–        1       skipper   skipper     0 Jul 17 17:08     skipper.file
$ rm -f skipper.file
$ ls -la
drwxrwxr-t    2     skipper   rico    4096 Jul 17 17:26     .
drwxr-xr-x     39   root          root    4096 Jul 17 16:59    ..

now we proved that the skipper (owner of the /sticky directory) can delete all files.

Comments

Popular posts from this blog

Creating Multiple VLANs over Bonding Interfaces with Proper Routing on a Centos Linux Host

In this post, I am going to explain configuring multiple VLANs on a bond interface. First and foremost, I would like to describe the environment and give details of the infrastructure. The server has 4 Ethernet links to a layer 3 switch with names: enp3s0f0, enp3s0f1, enp4s0f0, enp4s0f1 There are two bond interfaces both configured as active-backup bond0, bond1 enp4s0f0 and enp4s0f1 interfaces are bonded as bond0. Bond0 is for making ssh connections and management only so corresponding switch ports are not configured in trunk mode. enp3s0f0 and enp3s0f1 interfaces are bonded as bond1. Bond1 is for data and corresponding switch ports are configured in trunk mode. Bond0 is the default gateway for the server and has IP address 10.1.10.11 Bond1 has three subinterfaces with VLAN 4, 36, 41. IP addresses are 10.1.3.11, 10.1.35.11, 10.1.40.11 respectively. Proper communication with other servers on the network we should use routing tables. There are three

PowerShell Script for Switching Between Multiple Windows

Windows PowerShell has strong capabilities. I have a separate computer with a big lcd screen in which I am watching regularly some web based monitoring applications. So I need those application windows switch between on a timely basis. Then I wrote this simple powershell script to achieve this. You can change it according to your needs.