0% found this document useful (0 votes)
18 views8 pages

Changing File Ownership

changing file ownership notes

Uploaded by

shiyaprisi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

Changing File Ownership

changing file ownership notes

Uploaded by

shiyaprisi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

6.

7 CHANGING THE FILE


OWNERSHIP

Prishla.S
III B.Sc Comp.Science
FILE OWNERSHIP
Every file and directory on your Unix/Linux system is
assigned 3 types of owner,.
User - is the owner of the file. By default, the person
who created a file becomes its owner. Hence, a user is
also sometimes called an owner.
Group - can contain multiple users. All users belonging
to a group will have the same Linux group permissions
access to the file.
Other – Any other user who has access to a file. This
person has neither created the file, nor he belongs to a
usergroup who could own the file. Practically, it means
everybody else. Hence, when you set the permission
for others, it is also referred as set permissions for the
world.
CHANGING FILE OWNERSHIP

File ownership is a feature often ignored by


many users. By now, you know well enough that
when a user Kumar from a metal group creates a
file, then he becomes the owner of the file and also
metal becomes the group owner. It’s only Kumar who
can change the major file, attributes like permission
and group ownership. No member of the metal
group (except Kumar) can change the attribute.
However, when Sharma copies, the ownership of the
copy is transferred to Sharma, and he can then
manipulate the attribute of copy at will.
There are two commands meant to change the
ownership of the file or directory- chown and chgrp

By default, the owner cannot use


the chown command to change the owner of a file
or directory.
In addition, the owner can only use
the chgrp command to change the group of a file to
a group in which the owner belongs by default.

Unix system differs in the way they restrict the


usage of these two commands.
On BSD based systems, only the system
administrator can change a file’s owner with
chown . On the same system, the restrictions are
less severe when it comes to changing groups with
CHOWN- CHANGING FILE OWNER
We’ll first consider the behaviour of BSD-based chown
(change owner) that has been adopted by many systems
including Solaris and Linux. The command is used in this way:
chown options owner [:group] file(s)
chown transfers ownership of a file to a user, and it seems that
it can optionally change the group as well. The command
requires the user-id (UID) of the recipients, followed by one or
more filenames.
Changing ownership requires superuser permissions, so lets
first change our status to that of superuser with the su
command.
$ su This is the root password!
password : ********* This is another shell
#_
After the password is sucessfully entered, su returns a
#prompt, the same prompt used by root. su lets us acquire
superuser status, if we know the root password.
To now renounce the ownership of the file note to Sharma ,
use chown in the following way:

# ls -1 note
-rwxr-----x 1 kumar metal 347 May 10
20:30 note
# chown sharma note ; 1s -1 note
-rwxr-----x 1 sharma metal 347 May 10
20:30 note

# exit switches from


superuser’s shell
$_ to user’s login
shell
Once ownership of a file that has been given away to
sharma, the user file permissions that previously applied to
kumar now apply to sharma . Thus, kumar can no longer edit
CHGRP: CHANGING GROUP OWNER
By default, the group owner of a file is the group
to which the owner belongs. The chgrp (change
group) command changes a file’s group owner. On
systems that implements the BSD version of chgrp, a
user can change the group owner of a file, but only
to a group to which she also belongs. Yes,a user can
belong to more than one group, and the one shown
in /etc/passwd is the user’s main group.
chgrp shares a similar syntax with chown .
In the following example, kumar changes the group
ownership of dept.1st to dba(no superuser permission
required)
$ ls -1 dept.1st
-rw-r- - r- - 1 kumar metal 139 Jun 8
16:43 dept.1st
$ chgrp dba dept.1st ; ls -1 dept.1st
- rw-r- - r- - 1 kumar dba 139 Jun 8
16:43 dept.1st
This command will work on a BSD –based system if kumar is
also a member of dba group. If he is not, then only the superuser can
make the command work . Note that kumar will reverse this action
and restore the previous group ownership (to metal) because he is
still owner of a file and consequently retains all rights related to it.
Using chown to Do Both As an added benefit, UNIX allows the
administrator to use only chown to change both owner and group.
The syntax requires the two arguments to be seperated by a:

chown sharma : dba dept .1st ownership to


sharma , group to dba

Like chmod, both chown and chgrp use the –R option to perform
their operations in a recursive manner.

You might also like