File ownership and permissions
Each file and directory belongs to a specific user ID and group ID, and has a set of permissions (also referred to as modes) associated with it.
You can use these utilities to control ownership and permissions:
| To: | Use: |
|---|---|
| Specify the permissions for a file or directory | chmod |
| Change the owner (and optionally the group) for a file or directory | chown |
| Change the group for a file or directory | chgrp |
For details, see the Utilities Reference.
You can change the permissions and ownership for a file or directory only
if you're its owner or you're logged in as root.
If you want to change both the permissions and the ownership,
change the permissions first.
Once you've assigned the ownership to another user, you can't change the
permissions.
Permissions are divided into these categories:
- u
- Permissions for the user (i.e., the owner)
- g
- Permissions for the group.
- o
- Permissions for others (i.e., everyone who isn't in the group).
Each set of permissions includes:
- r
- Read permission.
- w
- Write permission.
- x
- Execute permission. For a directory, this is permission to list or search the directory.
- s or S
- Setuid or setgid (see below).
- t or T
- Sticky bit (see below).
For example, if you list your home directory (using ls -al), you might get output like this:
total 94286 drwxr-xr-x 18 barney techies 6144 Sep 26 06:37 ./ drwxrwxr-x 3 root root 2048 Jul 15 07:09 ../ drwx------ 2 barney techies 4096 Jul 04 11:17 .AbiSuite/ -rw-rw-r-- 1 barney techies 185 Oct 27 2000 .Sig -rw------- 1 barney techies 34 Jul 05 2002 .cvspass drwxr-xr-x 2 barney techies 2048 Feb 26 2003 .ica/ -rw-rw-r-- 1 barney techies 320 Nov 11 2002 .kshrc -rw-rw-r-- 1 barney techies 0 Oct 02 11:17 .lastlogin drwxrwxr-x 3 barney techies 2048 Oct 17 2002 .mozilla/ drwxrwxr-x 11 barney techies 2048 Sep 08 09:08 .ph/ -rw-r--r-- 1 barney techies 254 Nov 11 2002 .profile drwxrwxr-x 2 barney techies 4096 Jul 04 09:06 .ws/ -rw-rw-r-- 1 barney techies 3585 Dec 05 2002 123.html
The first column is the set of permissions. A leading d indicates that the item is a directory; see Types of files, earlier in this chapter.
If the permissions are followed by a plus sign (+), the file or directory has an
access control list that further specifies the permissions.
For more information, see
Access Control Lists (ACLs), below.
You can also use octal numbers to indicate the modes; see chmod in the Utilities Reference.