How to Change the Owner of a File
Use the following procedure to change the ownership of a file.
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.
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.
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.
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 |
Changing File Permissions
The chmod command enables you to change the permissions on a file. You must be superuser or the owner of a file or directory to change its permissions.
You can use the chmod command to set permissions in either of two modes:
Absolute Mode - Use numbers to represent file permissions (the method most commonly used to set permissions). When you change permissions by using the absolute mode, you represent permissions for each triplet by an octal mode number.
Symbolic Mode - Use combinations of letters and symbols to add or remove permissions.
The following table lists the octal values for setting file permissions in absolute mode. You use these numbers in sets of three to set permissions for owner, group, and other (in that order). For example, the value 644 sets read and write permissions for owner, and read-only permissions for group and other.
Table 15-5 Setting File Permissions in Absolute Mode
Octal Value | File Permissions Set | Permissions Description |
---|---|---|
0 | --- | No permissions |
1 | --x | Execute permission only |
2 | -w- | Write permission only |
3 | -wx | Write and execute permissions |
4 | r-- | Read permission only |
5 | r-x | Read and execute permissions |
6 | rw- | Read and write permissions |
7 | rwx | Read, write, and execute permissions |
You can set special permissions on a file in absolute or symbolic modes. However, you cannot set or remove setuid permissions on a directory by using absolute mode. You must use symbolic mode. In absolute mode, you set special permissions by adding a new octal value to the left of the permission triplet. The following table lists the octal values to set special permissions on a file.
Table 15-6 Setting Special Permissions in Absolute Mode
Octal Value | Special Permissions Set |
---|---|
1 | Sticky bit |
2 | setguid |
4 | setuid |
The following table lists the symbols for setting file permissions in symbolic mode. Symbols can specify whose permissions are to be set or changed, the operation to be performed, and the permissions that are being assigned or changed.
Table 15-7 Setting File Permissions in Symbolic Mode
Symbol | Function | Description |
---|---|---|
u | Who | User (owner) |
g | Who | Group |
o | Who | Others |
a | Who | All |
= | Operator | Assign |
+ | Operator | Add |
- | Operator | Remove |
r | Permission | Read |
w | Permission | Write |
x | Permission | Execute |
l | Permission | Mandatory locking, setgid bit is on, group execution bit is off |
s | Permission | setuid or setgid bit is on |
S | Permission | suid bit is on, user execution bit is off |
t | Permission | Sticky bit is on, execution bit for others is on |
T | Permission | Sticky bit is on, execution bit for others is off |
The who operator permission designations in the function column specifies the symbols that change the permissions on the file or directory.
who | Specifies whose permissions are to be changed. |
operator | Specifies the operation to be performed. |
permissions | Specifies what permissions are to be changed. |
How to Change Permissions in Absolute Mode
Use the following procedure to change permissions in absolute mode.
If you are not the owner of the file or directory, become superuser or assume an equivalent role.
Only the current owner or superuser can use the chmod command to change file permissions on a file or directory.
Change permissions in absolute mode by using the chmod command.
$ chmod nnn filename
nnn
Specifies the octal values that represent the permissions for the file owner, file group, and others, in that order. See Table 15-5 for the list of valid octal values.
filename
Specifies the file or directory.
Note - If you use the chmod command to change the file group permissions on a file with ACL entries, both the file group permissions and the ACL mask are changed to the new permissions. Be aware that the new ACL mask permissions can change the permissions for additional users and groups who have ACL entries on the file. Use the getfacl command to make sure that the appropriate permissions are set for all ACL entries. For more information, see the getfacl(1) man page.
Verify that the permissions of the file have changed.
$ ls -l filename