Changing file ownership
As a regular user,you cannot change
ownership of a file or a directory to have them belong to another user.you can
change ownership as the root user.
For ex: say you created a file and
used chown command to change the ownership permission
The file was owned by
fabien,after running the command chown sith path,the ownership changed to
sith.but left the group as fabien
To change both user and group to
sith you need to type the following command.
Now you can see that both the user
and the group changed to sith.
The chown command can be used
recursively as well. Using the recursive options (-R) is helpful if you need to
change a whole directory structure to ownership by a particular user .
For ex: if you inserted a USB drive,which is mounted on the /media/myusb directory,and wanted to give full
ownership to the contents of the drive to the user fabien,you could type the
following.
#chown -R fabien:fabien
/media/myusb
Changing group ownership
CHGRP(CHange GRouP) is the command which is
useful to change group associated to a file/folder from one group to othe.
syntax : chgrp <groupname> file/folder
Here in this example we have change the group ownership from fabien to sith
Change
group ownership all the files located in /var/apache to group:apache
#chgrp -R apache /var/apache
Difference between chown and chgrp
1) chown command is used to change ownership as well as group name associated to different one, where as chgrp can change only group associated to it.2) Many people say that regular user only able to use chgrp to change the group if the user belongs to them. But it’s not true a user can use chown and chgrp irrespective to change group to one of their group because chown is located in /bin folder so every can use it with some limited access.
No comments:
Post a Comment