1836360 Members
2121 Online
110100 Solutions
New Discussion

manage file

 
SOLVED
Go to solution
peterchu
Super Advisor

manage file

In my system , there are some files ( the file name is begins with "tp" ) will be generated to a directory , but all these files are own by root ( because it is generated by system ) , so that general user can't delete it , if I want the general user can delete the file in this directory , could suggest what is the best way ? is it possible to change the file permission to 666 once the file is generated ? or other better method ?
11 REPLIES 11
Ranjith_5
Honored Contributor

Re: manage file

Hi Peter,

1. Set sticky bit on this directory. This way only the owner of the file can delete it. chmod 1777 is a normal permission set to world writable permission. in this way you can share this folder among users with a good security since only the owners of the file will be able to delete it. But any one can create new files.

2.set the umask 111 so that the default permission will be 666 as u mentioned. Put umask 777.

Can be added to /etc/profile either of the following way.

umask u=rwx,g=rx,o=rx symbolic mode
umask a=rx,u+w symbolic mode
umask 022 numeric mode

HTH.
Regards,
Syam
Ranjith_5
Honored Contributor

Re: manage file

sorry....... Ignore the line "put umask 777" in my last post. No pts for this post please.

Regards,
peterchu
Super Advisor

Re: manage file

thx reply ,

Because the file ( eg. tpaaa.txt , tpbbb.txt ) is generated by system , the owner is root:root , the permission is 644 , if I want to let all users can delete this file , what can I do ? thx.
Ranjith_5
Honored Contributor
Solution

Re: manage file

Hi Peter,

Generae a small script only to delete specific files with SUID , and no write access permission on this script.

could be similar to the following

#!/usr/bin/sh

rm
Regards
Syam

Ranjith_5
Honored Contributor

Re: manage file

Other option is to set a cron job to change the ownerships of this files in a required interval of time say once in an hour or so.

Regards,
Syam
A. Clay Stephenson
Acclaimed Contributor

Re: manage file

The ability to delete a file is not controlled by the permissions on the file but on the directory that houses the file. Change the directory mode to 0777 and anyone can delete any file. Note the leading zero as I am telling you to specifically clear the sticky bit (1000) if set.
If it ain't broke, I can fix that.
peterchu
Super Advisor

Re: manage file

thx reply ,

If I want to let a specific user eg. edp_usr:EDP can delete / create any file at a directory eg. /home/EDP , even what permission/owner of the file in the dirctory , could suggest what can I do ? thx
Ranjith_5
Honored Contributor

Re: manage file

Peter,

If it a home directory of a user then ,he will have the permissions to delete files by default.

You can set permission of 770 to this directory. Make sure that the edp user falls under the group which is having write access to this directory.

Regards,
Syam
peterchu
Super Advisor

Re: manage file

thx reply , i want to keep the permission of the directory is 1777 but can let a specific user can delete any files under the directory , as I know "chacl" can do it , but it is for a existing file , if I want to use this function on a directory ( not existing file ) , is it possible ? thx
Ranjith_5
Honored Contributor

Re: manage file

Hi Peter,

the 17777 permission is called as sticky bit. can be set on any desired directoty.

Regards,
Gerhard Roets
Esteemed Contributor

Re: manage file

Hi Peterchu

I assume the files is machine created ... so why not in the script which creates them which should obviously know the filename ... just add a chmod to the appropriate script.

Alternatively ... just use a cronjob to do this "chmod" say every 30 minutes ... wont be on the fly but cleanups should be possible.

HTH
Gerhard