Issue
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.
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.
Solution
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.
Answered By - CesarB Answer Checked By - Marilyn (WPSolving Volunteer)