chmod: Changing a File’s Permissions

When you create a file, its initial permissions depend on your umask value (which is discussed later). You can change a file’s permissions with the chmod command or the chmod( ) system call. You can change a file’s permissions only if you are the file’s owner. The one exception to this rule is the superuser: if you are logged in as the superuser, you can change the permissions of any file.[67]

In its simplest form, the chmod command lets you specify which of a file’s permissions you wish to change. This usage is called symbolic form. The symbolic form of the chmod command[68] has the form:

chmod [-Rfh] [agou][+-=][rwxXstugol] filelist

This command changes the permissions of filelist, which can be either a single file or a group of files. The letters agou specify whose privileges are being modified. You may provide none, one, or more, as shown in Table 6-7.

Table 6-7. Whose privileges are being modified?

Letter

Meaning

a

Modifies privileges for all users

g

Modifies group privileges

o

Modifies others’ privileges

u

Modifies the owner’s privileges

The symbols specify what is supposed to be done with the privilege. You must type only one symbol, as shown in Table 6-8.

Table 6-8. What to do with privilege

Symbol

Meaning

+

Adds to the current privilege

-

Removes from the current privilege

=

Replaces the current privilege

The last letters specify which privilege will be modified, as shown in Table 6-9.

Table 6-9. Which privileges are being ...

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.