Operating System - HP-UX
1833729 Members
2670 Online
110063 Solutions
New Discussion

Why only root can set "sticky bit" on a file?

 
SOLVED
Go to solution
yyghp
Super Advisor

Why only root can set "sticky bit" on a file?

Hi there,

I noticed that I couldn't successfully set "sticky bit" on a file with normal user, except root.

When I login as root:
# ll abc
-rwxrwx--- 1 root sys 0 Apr 20 08:59 abc
# chmod o+t abc
# ll abc
-rwxrwx--T 1 root sys 0 Apr 20 08:59 abc

But if I login as non-root user, it didn't add "T" to the mode.

Is that normal?

( NOTE: I just need to set such mode to mark a "flag" on the file, not to use as the purpose of sticky bit. )

Thanks!
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: Why only root can set "sticky bit" on a file?

Only root - or the owner - can set the sticky bit.


Pete

Pete
Geoff Wild
Honored Contributor

Re: Why only root can set "sticky bit" on a file?

Yes that is normal - only root can set the sticky bit.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Arunvijai_4
Honored Contributor
Solution

Re: Why only root can set "sticky bit" on a file?

Hi,

Check this HP-UX FAQ,

http://www.faqs.org/faqs/hp/hpux-faq/section-70.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Geoff Wild
Honored Contributor

Re: Why only root can set "sticky bit" on a file?

Actually - a regular user can't set the sticky bit - usually, it is used on a directory - for example - say you have a directory where many users put files - setting the sticky bit will only allow the owner of a file the ability to delete it - not the other users.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor

Re: Why only root can set "sticky bit" on a file?

Hi:

One would expect this behavior. After all, the sticky bit causes the swap image of the program text (code) to be saved when the last user of the file terminates execution. This means that the *next* instantiation of the process is slightly faster than for a file without the saved image.

Thus, why would one want any user to be able to arm this behavior?!

By the way, "T" is shown when there is no execute bit set on the world permissions but the sticky bit is on. A lowercase ("t") denotes a stick bit on along with execute permissions for everyone.

Regards!

...JRF...

yyghp
Super Advisor

Re: Why only root can set "sticky bit" on a file?

Thanks a lot guys!
The purpose I am doing this is to mark a "status flag" on that file for script usage.
Now, since I can't use "sticky bit" for this, I would like to use "x" in "world", like this:

$ chmod o+x

But how can I "test" whether "x" bit is set in "world" permission after that?
I think I can't use "test -x " because it will return "true" if "x" bit is set in "user"/"group" permission. But now, I only want to "test" whether "x" bit is set in "world"/"other" section.
What's the easiest way to "test" this?
Thanks again!
Pete Randall
Outstanding Contributor

Re: Why only root can set "sticky bit" on a file?

Sorry - brain cramp!

I was reading sticky bit but thinking suid bit. I even tested it to make sure and it works just fine for the suid bit.


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: Why only root can set "sticky bit" on a file?

Hi (again):

One way to test the state of the execute bit for the "world" is to examine the output of a simple 'ls -l' thusly:

# ls -l myfile|perl -lne 'print "1" if /^-.{8}x/'

If world-execute permissions exist, a one (1) is printed, otherwise nothing is returned.

You can capture this in a variable of your choice and test it as necessary.

Regards!

...JRF...