1827286 Members
1705 Online
109717 Solutions
New Discussion

Re: sticky bit

 
SOLVED
Go to solution
Victor_5
Trusted Contributor

sticky bit

What is the sticky bit? Where can I find doc about it?
12 REPLIES 12
Byron Myers
Trusted Contributor
Solution

Re: sticky bit

man ls
this will tell you what it is (search for sticky) - it is the "s" and "S" modes. It is set with chmod, see man on chmod with u+s, g+s, o+s options.
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
A. Clay Stephenson
Acclaimed Contributor

Re: sticky bit

Hi Shawn:

The sticky bit (sometimes called the sticky text bit) is the 1000 (octal) component of a files modes. To set the sticky bit on an executable, chmod 1755 a.out. Yiu can man chmod (2) for details. The idea behind is it that after a program has started, the 'text' - instructions portion of the program is retained in memory. If you have many users using a program like vi then setting the sticky bit makes the new load of the program mush faster. However, if you have many users
running vi, the text is already loaded and is shared by the users anyway. Here is the difference. Suppose I run vi with then sticky bit set, when I exit the text hangs around. The next launch of vi can immediately use that that text segment. However, if vi was already running the text could still be used by another process even without the sticky bit being set.

Hope this helps, Clay
If it ain't broke, I can fix that.
Santosh Nair_1
Honored Contributor

Re: sticky bit

From the chmod man page:

Add or delete the save-text-image-on-file-
execution (sticky bit) permission. Useful only if u is expressed or implied in who. See chmod(2).

which basically translate into this:

If the sticky bit permissions is on for an executable, if the process is sharable, the process does not get flushed from memory after the last user terminate.
If the the bit is turned on for a directory, then only the owner of the file and root can delete files created in that directory.

-Santosh
Life is what's happening while you're busy making other plans
A. Clay Stephenson
Acclaimed Contributor

Re: sticky bit

Hi again Shawn:

I suppose I should also cover the sticky bits meaning in a directory. In that case, only the owner of a file within that directory, the owner of the directory, or a user with approproiate privilieges can rm the file. The sticky bit for directories is set exactly the same way, chmod 1xxx mydir.

Clay
If it ain't broke, I can fix that.
Byron Myers
Trusted Contributor

Re: sticky bit

Clay, or others: how do you tell if the "t" sticky bit is set on a file?
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
Joseph C. Denman
Honored Contributor

Re: sticky bit

There permissions on the file will show as

-rwxr-xr-T

...jcd...
If I had only read the instructions first??
Bernie Vande Griend
Respected Contributor

Re: sticky bit

There are 3 uses of the sticky bit: (2 were already mentioned;
1) on a file: helps keeps portions of the program in memory to make it faster to run again.
2) on a directory: you must own the file in the directory in order to delete it.
3) on a link. This is called a transitional link which HP uses to bridge the gap between older 9.X programs and the latest OS. This can only be set with the program /opt/upgrade/tlinstall. /bin and /lib are examples of this.

And you see the sticky bit when an ls -l shows a "t" in the last position.
Ye who thinks he has a lot to say, probably shouldn't.
Peter_17
Frequent Advisor

Re: sticky bit

So, with this in mind, should the /tmp directory have the sticky bit set?

Pete
Santosh Nair_1
Honored Contributor

Re: sticky bit

I typically set the sticky bit for both /tmp and /var/tmp .

-Santosh
Life is what's happening while you're busy making other plans
Peter_17
Frequent Advisor

Re: sticky bit

Is there a security implication of not having the sticky bit set on /tmp (and /var/tmp)? And; Is it considered good practice to have it set on these directories?

Pete
Santosh Nair_1
Honored Contributor

Re: sticky bit

I'm not sure that its a security issue but considering many program write temporary file in /tmp and /var/tmp, there could be some bad implications if the someone deleted the file(s) in tmp while they're in use.

I would say its good practice to set the sticky bit on those directories.

Just my 2 cents.

-Santosh
Life is what's happening while you're busy making other plans
Patrick Wallek
Honored Contributor

Re: sticky bit

Do not confuse the 'sticky bit' (T) with the setuid bit (s). They are perform vastly different functions. The setuid bit is often (mistakenly) referred to as the sticky bit.

Make sure you know which functionality you need before you set the bit.