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

Sending Jboss Server Logs to Logstash Using Filebeat with Multiline Support

In addition to sending system logs to logstash, it is possible to add a prospector section to the filebeat.yml for jboss server logs. Sometimes jboss server.log has single events made up from several lines of messages. In such cases Filebeat should be configured for a multiline prospector.
Filebeat takes lines do not start with a date pattern (look at pattern in the multiline section "^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}" and negate section is set to true) and combines them with the previous line that starts with a date pattern.

server.log file excerpt where DatePattern: yyyy-MM-dd-HH and ConversionPattern: %d %-5p [%c] %m%n
Logstash filter: