I am trying to create a file in the /tmp
directory (working on a Linux UBUNTU 7.10), that has read/write/execute access for any user.
So I am using the
open(fileName,O_CREAT|O_RDWR,0777)
function to create the file (from a C program) in user1
account and I would like user2
to be able to write to the specific file.
However, when I check the /tmp
directory, using
ls -l
I see that I do not have the write access permission for user2
(considering the fact that user1
created it, I have write access for user1
, but user2
, who is considered to be "others" does not have any access).
I have tried to use mode 0766
in the open
function (and such combinations of 7
and 6
for modes), so that I may get write access for user2
, but I still don't have the required access.
The /tmp and /var/tmp directories requires special permissions. This directory has Sticky Bit permissions. Many applications will show errors or fail if they are not able to write to /tmp with the appropriate permissions. The 't' at the end symbolizes that the sticky bit is set.
chmod o-rwx foldername To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.
Removing read and write permission for group and others : chmod go-rw . Removing read permissions for others : chmod o-r . Assigning write permission to group and overriding existing permission: chmod g=w .
You have to set your umask to 000. The bits on the umask are removed from the permission you have chosen, and the default umask is usually 022 or 002.
Note that things like default ACLs and SELinux labels might also affect the readability and writability of files. Use getfacl to see ACLs and ls -Z to see SELinux labels; for SELinux, you also have to know which policies are active and what effect they have. The presence of ACLs can also be seen on ls -l as a + character after the permissions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With