Sponsored Content
Full Discussion: Sticky Bit
Top Forums Shell Programming and Scripting Sticky Bit Post 302354171 by methyl on Thursday 17th of September 2009 10:15:14 AM
Old 09-17-2009
See "man 2 chmod" for an explanation of the sticky bit on individual files. It's more about caching than permissions.


The sticky bit does have a use for directories in some O/S.
Code:
mkdir mydir
chmod 1770 mydir
chown myuser:mygroup mydir
cd mydir
touch myfile
chmod 640 myfile
chown myuser:mygroup myfile

The file myfile can be read by anyone in mygroup but the sticky bit on the directory stops them deleting the file with error "not owner".
Try it. Not all O/S behave the same way.


A less complicated way to protect a file is to own the directory and the file and only allow write access to yourself. In this example users in your group can see the file and its contents but not make changes.
Code:
mkdir mydir
chown myuser:mygroup mydir
chmod 750 mydir
cd mydir
touch myfile
chmod 640 myfile
chown myuser:mygroup myfile


Last edited by methyl; 09-17-2009 at 11:18 AM.. Reason: layout - was too wide
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sticky bit

I have a questions, whose answer may be very obvious: Of what use is the sticky-bit permission on a Unix system? I have looked at the chmod(1) man page on our HP-UX playground system, and haven't been given much explanation: Add or delete the save-text-image-on-file- execution (sticky... (3 Replies)
Discussion started by: LivinFree
3 Replies

2. UNIX for Dummies Questions & Answers

sticky bit??

I have a script that I want to be able to let user 'wcs1234' execute it, but when it runs, it will do so under the higher authority of 'cdunix'. It is my understanding that I accomplish this with a sticky bit. I have tried every variation of this but am unable to get this to work. my script is... (2 Replies)
Discussion started by: hedrict
2 Replies

3. UNIX for Dummies Questions & Answers

sticky bit

What command string would you use to set the sticky bit on a directory that you own? (2 Replies)
Discussion started by: mma_buc_98
2 Replies

4. UNIX for Dummies Questions & Answers

Sticky Bit

I have the sticky bit set on my /tmp directory, but users are still able to remove files that are not owned by them. Does the /etc/group file get invloved in securing these files ?? (1 Reply)
Discussion started by: rob11g
1 Replies

5. UNIX for Dummies Questions & Answers

Sticky Bit

Hi, could anyone please send me a link to learn/ know more about sticky bits? I am still not clear on the application of using a sticky bits. Thanks for your help. Regards, UP (3 Replies)
Discussion started by: teenu18
3 Replies

6. UNIX for Dummies Questions & Answers

Question regarding permision and seguid bit (sticky bit)

Hi , I am having file permision as drwxrwsr_x I kwo for deleting a file in the diretory i need w permsion as well .. Say if i am having the permsion as drwxrwsrwx - wil any one can delete the files in the directory .. And one more question what is the s doing there ..... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

7. UNIX for Dummies Questions & Answers

Sticky Bit????

HI What is sticky bit? how can be see if the sticky bit for file is set? WHat is meaning of sticky bit set on Directory? What is the syntax to set the sticky bit? With example Thanks (10 Replies)
Discussion started by: skyineyes
10 Replies

8. UNIX for Advanced & Expert Users

sticky bit

Hi, I understand the purpose of sticky bit on directories. But I am not very clear about what the sticky bit do on a file. Can any one explain me in detail and with example please. Thanks in advance. (1 Reply)
Discussion started by: praveen_b744
1 Replies

9. AIX

Sticky Bit

What is sticky bit ...and where we aill use this.. how to set this bit in files and directories (1 Reply)
Discussion started by: udtyuvaraj
1 Replies

10. AIX

sticky bit

as far as i understand, if sticky bit is set on a directory, the files created under tht directory cannot be deleted by ordinary user... but we can do ths by permission itself,,, tht's assign only read permission to tht dirrectory wht 's the difference? (1 Reply)
Discussion started by: udtyuvaraj
1 Replies
STICKY(7)					       BSD Miscellaneous Information Manual						 STICKY(7)

NAME
sticky -- Description of the `sticky' (S_ISVTX) bit functionality DESCRIPTION
A special file mode, called the sticky bit (mode S_ISVTX), is used to indicate special treatment for directories. See chmod(2) or the file /usr/include/sys/stat.h Sticky files For regular files, the use of mode S_ISVTX is reserved and can be set only by the super-user. NetBSD does not currently treat regular files that have the sticky bit set specially, but this behavior might change in the future. Sticky directories A directory whose ``sticky bit'' is set becomes a directory in which the deletion of files is restricted. A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the super-user. This feature is usefully applied to directories such as /tmp which must be publicly writable but should deny users the license to arbitrarily delete or rename each others' files. Any user may create a sticky directory. See chmod(1) for details about modifying file modes. HISTORY
The sticky bit first appeared in V7, and this manual page appeared in section 8. Its initial use was to mark sharable executables that were frequently used so that they would stay in swap after the process exited. Sharable executables were compiled in a special way so their text and read-only data could be shared amongst processes. vi(1) and sh(1) were such executables. This is where the term ``sticky'' comes from - the program would stick around in swap, and it would not have to be fetched again from the file system. Of course as long as there was a copy in the swap area, the file was marked busy so it could not be overwritten. On V7 this meant that the file could not be removed either, because busy executables could not be removed, but this restriction was lifted in BSD releases. To replace such executables was a cumbersome process. One had first to remove the sticky bit, then execute the binary so that the copy from swap was flushed, overwrite the executable, and finally reset the sticky bit. Later, on SunOS 4, the sticky bit got an additional meaning for files that had the bit set and were not executable: read and write operations from and to those files would go directly to the disk and bypass the buffer cache. This was typically used on swap files for NFS clients on an NFS server, so that swap I/O generated by the clients on the servers would not evict useful data from the server's buffer cache. BUGS
Neither open(2) nor mkdir(2) will create a file with the sticky bit set. BSD
May 10, 2011 BSD
All times are GMT -4. The time now is 01:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy