Let's take a look at the last special permission, which is called the sticky bit. 1
The sticky bit is applied mainly to directories and if it set on a directory 2
then a user may only delete files that he owns or for which it has explicit right permission granted, 3
even when he has right access to the directory. 4
This is designed for directories like /tmp, which are world-writable, but where it may not be desirable 5
to allow any user to delete files at will. 6
This allows you to create a directory that everyone, including the processes the users launch, can use 7
as a shared file storage. 8
The files are protected because again, no one can delete anyone else's file. 9
Let's take a look at an example to see how the sticky bit works. 10
As root I'm creating such a shared storage directory, so I'm becoming root mkdir / tmp and I want 11
it to be world writable, anyone can have its own files there 12
chmod 777 and the directory 13
Now, a random non privileged user is coming and creating some files in that directory. 14
So touch 15
file1 and file2. 16
And just to be sure that, no one else is able to remove his files, the user changes the file's permissions 17
to 600. 18
So chmod 600 and the files. 19
Normally, no other user should be allowed to delete these files; the files permissions do not allow 20
anyone to read or write the files, but the parent directories permissions allow that. 21
As we've already seen in the file permissions section if a user has permissions on a directory, he can 22
remove all the files in that directory, even though the file's permissions would not allow it. 23
So a second non privileged user, is coming and trying to remove one of the first user's file. 24
I'll pick a random user. 25
toor so su toor 26
I am toor. 27
I'm moving to that directory and trying to remove a file. 28
rm -rf file1.txt . And the file was removed, which is not good; now as root I set the sticky 29
bit on that directory. 30
I'm exiting toor and be root again; to set the sticky bit prepend one to the existing permissions, so 31
chmod 1 and the existing permissions. 32
Or if you want to use the symbolic mode 33
run chmod o+t and the directory. 34
To verify if the sticky bit is applied or not run ls -l command. 35
Simply look at the position of the execution permission for the others class; the letter t at 36
that position means that the sticky bit is set. 37
If you see a capital T instead of a small t, it indicates that for the others class, there is no 38
executable permission applied to that directory. 39
However, this is not common at all. 40
Having the sticky bit set on /temp directory, I'll try as a non unprivileged user to remove the file 41
of the first user. 42
I'm becoming toor again. 43
And I'm moving to /temp directory. 44
And I'm trying to remove file2.txt 45
And this time, the user cannot delete the file. 46
This is what the sticky bit does. 47
Also note that the displayed message is operation not permitted and not permission denied. Other 48
shared directories with the sticky bit set are /var /tmp 49
And /tmp 50
users and processes can create files, and even though they can read and execute files owned by other 51
users, they are not allowed to remove them 52
at will. That's all about permissions. 53
You now have a good understanding of what they do, how to change them both using the numerical and 54
symbolic mode and check them. 55
This is a key concept in Linux. 56
So my advice is to take your time to deeply understand how file permissions work, practice them as 57
much as possible.