1832850 Members
2921 Online
110047 Solutions
New Discussion

set the file right

 
SOLVED
Go to solution
juno2
Super Advisor

set the file right

I have create a file on the system , how to set the file can only update/delete by the owner , the other users can read only ? thx
14 REPLIES 14
S.K. Chan
Honored Contributor
Solution

Re: set the file right

Two things to consider, the ownership of the file and its permission. Make sure the file is first owned by the user.
# chown skchan:users file
==> Change ownership of "file" to owner=skchan group=users
# chmod 644 file
==> That gives skchan (the owner) read and write permission. Other users in group "users" can only read and the rest of the world can only read.
In both cases man chmod and man chown wil give you the details.
juno2
Super Advisor

Re: set the file right

Thx ,

As I know , add the permission "t" can also prevent the user to delete the file , how to set it ?
Michael Tully
Honored Contributor

Re: set the file right

After the file has been created.

$ chmod 600 myfile

Before creation of the file set your umask

$ umask 077
$ touch mynewfile

Regards
Michael
"When I have trouble spelling, it's called fat finger syndrome"
Anyone for a Mutiny ?
S.K. Chan
Honored Contributor

Re: set the file right

I suppose I need to add one more comment. The ownership and permission of the directory where this file is located is also crucial. In order for file to be protected from deletion the dir permission should not allow a "write". A simply example is the /tmp dir which has a 777 (drwxrwxrwx) permission. Placing the above "file" in /tmp will allow anyone to delete it even though the permission of "file" is protected.
juno2
Super Advisor

Re: set the file right

how to set the file only the owner can delete/update , other users can only read ? thx
Michael Tully
Honored Contributor

Re: set the file right

The -t is called sticky bit. This is set so that people only delete their own files from within shared directories like /tmp
To set the permission of the directory/filesystem:

$ chmod +t /tmp

Regards
Michael
"When I have trouble spelling, it's called fat finger syndrome"
Anyone for a Mutiny ?
T G Manikandan
Honored Contributor

Re: set the file right

sticky bit "t" can only be set to the directories.

It means that only the owner or the super user can delete the file in the dir.

#chown 1777


THanks
juno2
Super Advisor

Re: set the file right

Thx Michael,

I try r method "chmod +t /tmp/file" , then the file premission changed to "-r--r--r-T" , however , i tried other users can still delete/update it ,even change the ownership after update the file. thx
juno2
Super Advisor

Re: set the file right

thx T G Manikandan ,
if it is file not dir , how to make this setting ? thx.
T G Manikandan
Honored Contributor

Re: set the file right

If that is required for files then you need to turn on ACL's.

Using ACL's you can do that.

check the man pages of setacl
T G Manikandan
Honored Contributor

Re: set the file right

check the man pages of acl.
juno2
Super Advisor

Re: set the file right

thx all,
except ACL , is there any other method can do that ?thx
T G Manikandan
Honored Contributor

Re: set the file right

how to set the file only the owner can delete/update , other users can only read.

If this is only what you want you can just do what Chan has replied.

Do a chmod 644 on the file so that only owner can update/delete others can only read?
What else you are looking for?
Jean-Louis Phelix
Honored Contributor

Re: set the file right

hi,

You've got all needed answers ... But I can summarize :

- Owner can update and others can only read :

chmod 644 file

- Owner can delete file but others can't, this is managed at the directory level (the directory where the file is located) :

. If directory belongs to the owner of the file :

chmod 755 dir

. If directory is a public one (like /tmp) :

chmod 1777 /tmp

Regards.
It works for me (© Bill McNAMARA ...)