BSD Newsletter.com
   Front | Info | Lists | Newsfeeds | Study Guide | What is BSD?
Advertisement: The OpenBSD PF Packet Filter Book: PF for NetBSD, FreeBSD, DragonFly and OpenBSD

BSD Links
·New Links
·Advocacy
·Drivers
·Events
·Flavours
·FAQs
·Guides
·Programming
·Security
·Software
·User Groups

This is the BSDA Study Guide Book written via a wiki collaboration. This is a work in progress. You may contribute to or discuss this specific page at http://bsdwiki.reedmedia.net/wiki/Modify_a_file__39__s_owner_or_group.html.

Modify a file's owner or group

Concept

Be able to modify a file's ownership as required. In addition, be aware of the importance of verifying one's own identity before creating files.

Introduction

A file's ownership can be changed by using the chown and chgrp tools. The change ownership tool can be used to change a file's user ID by using a username or user ID as an argument. A filename (or filenames) is the final argument.

Obviously changing a file's ownership can affect who can access to that file; thus the su(1) substitute user identity tool, can be used to gain access to file, which might otherwise be prevented due to the file's ownership.

The following example shows the current ownership of a file and then changes it to another user (by using a symbolic name and not a numeric ID):

$ ls -l math2.pl
-rwxr-xr-x  1 reed  wheel  734 Feb 14  2006 math2.pl

$ chown austin math2.pl

$ ls -l math2.pl
-rwxr-xr-x  1 austin  wheel  734 Feb 14  2006 math2.pl

The user ID can only be changed by the superuser (root), because a normal user should not be able to hide their data or bypass file system quotas by changing ownership. (TODO: any other reasons?) A file's group ID can be changed by any user to a group that they are a member of. (See section Determine identity and group membership about group membership.)

The chown utility can also change the file's group ID by prefixing a group name or group ID with a colon (:).

TODO: show example using numeric ID instead of symbolic name and ls -l -n

TODO: show example of using chown to change group

TODO: -R switch

TODO: point to section about file ownership attributes

TODO: document chgrp and show example

TODO: from concept" "In addition, be aware of the importance of verifying one's own identity before creating files."

TODO: after mentioning -R, mention mtree can be used to reset file onwerships based on a specification. show brief example maybe? or point to other section?

Examples

Practice Exercises

More information

chown(8), chgrp(1); su(1), mtree(8)



Front | Information | Lists | Newsfeeds