Changing a File’s Owner or Group

The chown and chgrp commands allow you to change the owner or the group of a file, respectively.

chown: Changing a File’s Owner

The chown command lets you change the owner of a file. Only the superuser can change the owner of a file under most modern versions of Unix.

The chown command has the form:

chown [ -fRh ] owner filelist

The -f and -R options are interpreted exactly as they are for the chmod and chgrp commands, if supported. The -h option is a bit different from that of chmod. Under chown, the option specifies that the owner of the link itself is changed and not what the link points to.

Other entries have the following meanings:

owner

The file’s new owner; specify the owner by name or by decimal UID

filelist

The list of files whose owner you are changing

Old and new chown behavior

In earlier versions of Unix, all users could run the chown command to change the ownership of a file that they owned to that of any other user on the system. This lets them “give away” a file. The feature made sharing files back and forth possible, and allowed a user to turn over project directories to someone else.

Allowing users to give away files can be a security problem because it makes a miscreant’s job of hiding his tracks much easier. If someone has acquired stolen information or is running programs that are trying to break computer security, that person can simply change the ownership of the files to that of another user. If he sets the permissions correctly, he ...

Get Practical UNIX and Internet Security, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.