System Administration Guide: Security Services

Changing File Ownership

This section describes how to change the ownership and group ownership of a file.

By default, the owner cannot use the chown command to change the owner of a file or directory. However, you can enable the owner to use the chown command by adding the following line to the system's /etc/system file and rebooting the system.


set rstchown = 0

For more information, see chown(1).

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. For example, if the owner of a file only belongs to the staff and sysadm groups, the owner can only change the group of a file to staff or sysadm group.

However, you can enable the owner to change the group of a file to a group in which the owner doesn't belong by adding the following line to the system's /etc/system file and rebooting the system.


set rstchown = 0

For more information, see chgrp(1).

Also, be aware that there can be other restrictions on changing ownership and groups on NFS-mounted file systems.

How to Change the Owner of a File

Use the following procedure to change the ownership of a file.

  1. Become superuser or assume an equivalent role.

  2. Change the owner of a file by using the chown command.


    # chown new-owner  filename
    

    new-owner

    Specifies the user name or UID of the new owner of the file or directory.  

    filename

    Specifies the file or directory. 

  3. Verify that the owner of the file has changed.


    # ls -l filename
    

Example—Changing the Owner of a File

In the following example, the ownership on myfile is changed to the user rimmer.


# chown rimmer myfile
# ls -l myfile
-rw-r--r--   1 rimmer   scifi   112640 May 24 10:49 myfile

How to Change Group Ownership of a File

Use the following procedure to change the group ownership of a file.

  1. Become superuser or assume an equivalent role.

  2. Change the group owner of a file by using the chgrp command.


    $ chgrp group filename
    

    group

    Specifies the group name or GID of the new group of the file or directory. 

    filename

    Specifies the file or directory. 

    For information on setting up groups, see “Managing User Accounts and Groups (Overview)” in System Administration Guide: Basic Administration.

  3. Verify that the group owner of the file has changed.


    $ ls -l filename
    

Example—Changing Group Ownership of a File

In the following example, the group ownership on myfile is changed to the group scifi.


$ chgrp scifi myfile
$ ls -l myfile
-rwxrw-- 1 rimmer scifi 12985 Nov 12 16:28 myfile