1 Each file has a set of @dfn{permissions} that control the kinds of
2 access that users have to that file. The permissions for a file are
3 also called its @dfn{access mode}. They can be represented either in
4 symbolic form or as an octal number.
7 * Mode Structure:: Structure of file permissions.
8 * Symbolic Modes:: Mnemonic permissions representation.
9 * Numeric Modes:: Permissions as octal numbers.
13 @section Structure of File Permissions
15 There are three kinds of permissions that a user can have for a file:
19 @cindex read permission
20 permission to read the file. For directories, this means permission to
21 list the contents of the directory.
23 @cindex write permission
24 permission to write to (change) the file. For directories, this means
25 permission to create and remove files in the directory.
27 @cindex execute permission
28 permission to execute the file (run it as a program). For directories,
29 this means permission to access files in the directory.
32 There are three categories of users who may have different permissions
33 to perform any of the above operations on a file:
39 other users who are in the file's group;
44 @cindex owner, default
45 @cindex group owner, default
46 Files are given an owner and group when they are created. Usually the
47 owner is the current user and the group is the group of the directory
48 the file is in, but this varies with the operating system, the
49 filesystem the file is created on, and the way the file is created. You
50 can change the owner and group of a file by using the @code{chown} and
51 @code{chgrp} commands.
53 In addition to the three sets of three permissions listed above, a
54 file's permissions have three special components, which affect only
55 executable files (programs) and, on some systems, directories:
60 set the process's effective user ID to that of the file upon execution
61 (called the @dfn{setuid bit}). No effect on directories.
64 set the process's effective group ID to that of the file upon execution
65 (called the @dfn{setgid bit}). For directories on some systems, put
66 files created in the directory into the same group as the directory, no
67 matter what group the user who creates them is in.
70 @cindex swap space, saving text image in
71 @cindex text image, saving in swap space
72 @cindex append-only directories
73 save the program's text image on the swap device so it will load more
74 quickly when run (called the @dfn{sticky bit}). For directories on some
75 systems, prevent users from removing files that they do not own in the
76 directory; this is called making the directory @dfn{append-only}.
80 @section Symbolic Modes
82 @cindex symbolic modes
83 @dfn{Symbolic modes} represent changes to files' permissions as
84 operations on single-character symbols. They allow you to modify either
85 all or selected parts of files' permissions, optionally based on
86 their previous values, and perhaps on the current @code{umask} as well
87 (@pxref{Umask and Protection}).
89 The format of symbolic modes is:
92 @r{[}ugoa@dots{}@r{][[}+-=@r{][}rwxXstugo@dots{}@r{]}@dots{}@r{][},@dots{}@r{]}
95 The following sections describe the operators and other details of
99 * Setting Permissions:: Basic operations on permissions.
100 * Copying Permissions:: Copying existing permissions.
101 * Changing Special Permissions:: Special permissions.
102 * Conditional Executability:: Conditionally affecting executability.
103 * Multiple Changes:: Making multiple changes.
104 * Umask and Protection:: The effect of the umask.
107 @node Setting Permissions
108 @subsection Setting Permissions
110 The basic symbolic operations on a file's permissions are adding,
111 removing, and setting the permission that certain users have to read,
112 write, and execute the file. These operations have the following
116 @var{users} @var{operation} @var{permissions}
120 The spaces between the three parts above are shown for readability only;
121 symbolic modes can not contain spaces.
123 The @var{users} part tells which users' access to the file is changed.
124 It consists of one or more of the following letters (or it can be empty;
125 @pxref{Umask and Protection}, for a description of what happens then). When
126 more than one of these letters is given, the order that they are in does
131 @cindex owner of file, permissions for
132 the user who owns the file;
134 @cindex group, permissions for
135 other users who are in the file's group;
137 @cindex other permissions
140 all users; the same as @samp{ugo}.
143 The @var{operation} part tells how to change the affected users' access
144 to the file, and is one of the following symbols:
148 @cindex adding permissions
149 to add the @var{permissions} to whatever permissions the @var{users}
150 already have for the file;
152 @cindex removing permissions
153 @cindex subtracting permissions
154 to remove the @var{permissions} from whatever permissions the
155 @var{users} already have for the file;
157 @cindex setting permissions
158 to make the @var{permissions} the only permissions that the @var{users}
162 The @var{permissions} part tells what kind of access to the file should
163 be changed; it is zero or more of the following letters. As with the
164 @var{users} part, the order does not matter when more than one letter is
165 given. Omitting the @var{permissions} part is useful only with the
166 @samp{=} operation, where it gives the specified @var{users} no access
171 @cindex read permission, symbolic
172 the permission the @var{users} have to read the file;
174 @cindex write permission, symbolic
175 the permission the @var{users} have to write to the file;
177 @cindex execute permission, symbolic
178 the permission the @var{users} have to execute the file.
181 For example, to give everyone permission to read and write a file,
182 but not to execute it, use:
188 To remove write permission for from all users other than the file's
196 The above command does not affect the access that the owner of
197 the file has to it, nor does it affect whether other users can
198 read or execute the file.
200 To give everyone except a file's owner no permission to do anything with
201 that file, use the mode below. Other users could still remove the file,
202 if they have write permission on the directory it is in.
209 Another way to specify the same thing is:
215 @node Copying Permissions
216 @subsection Copying Existing Permissions
218 @cindex copying existing permissions
219 @cindex permissions, copying existing
220 You can base a file's permissions on its existing permissions. To do
221 this, instead of using @samp{r}, @samp{w}, or @samp{x} after the
222 operator, you use the letter @samp{u}, @samp{g}, or @samp{o}. For
228 adds the permissions for users who are in a file's group to the
229 permissions that other users have for the file. Thus, if the file
230 started out as mode 664 (@samp{rw-rw-r--}), the above mode would change
231 it to mode 666 (@samp{rw-rw-rw-}). If the file had started out as mode
232 741 (@samp{rwxr----x}), the above mode would change it to mode 745
233 (@samp{rwxr--r-x}). The @samp{-} and @samp{=} operations work
236 @node Changing Special Permissions
237 @subsection Changing Special Permissions
239 @cindex changing special permissions
240 In addition to changing a file's read, write, and execute permissions,
241 you can change its special permissions. @xref{Mode Structure}, for a
242 summary of these permissions.
244 To change a file's permission to set the user ID on execution, use
245 @samp{u} in the @var{users} part of the symbolic mode and
246 @samp{s} in the @var{permissions} part.
248 To change a file's permission to set the group ID on execution, use
249 @samp{g} in the @var{users} part of the symbolic mode and
250 @samp{s} in the @var{permissions} part.
252 To change a file's permission to stay permanently on the swap device,
253 use @samp{o} in the @var{users} part of the symbolic mode and
254 @samp{t} in the @var{permissions} part.
256 For example, to add set user ID permission to a program,
257 you can use the mode:
263 To remove both set user ID and set group ID permission from
264 it, you can use the mode:
270 To cause a program to be saved on the swap device, you can use
277 Remember that the special permissions only affect files that are
278 executable, plus, on some systems, directories (on which they have
279 different meanings; @pxref{Mode Structure}). Using @samp{a}
280 in the @var{users} part of a symbolic mode does not cause the special
281 permissions to be affected; thus,
288 has @emph{no effect}. You must use @samp{u}, @samp{g}, and @samp{o}
289 explicitly to affect the special permissions. Also, the
290 combinations @samp{u+t}, @samp{g+t}, and @samp{o+s} have no effect.
292 The @samp{=} operator is not very useful with special permissions; for
300 does cause the file to be saved on the swap device, but it also
301 removes all read, write, and execute permissions that users not in the
302 file's group might have had for it.
304 @node Conditional Executability
305 @subsection Conditional Executability
307 @cindex conditional executability
308 There is one more special type of symbolic permission: if you use
309 @samp{X} instead of @samp{x}, execute permission is affected only if the
310 file already had execute permission or is a directory. It affects
311 directories' execute permission even if they did not initially have any
312 execute permissions set.
314 For example, this mode:
321 gives all users permission to execute files (or search directories) if
324 @node Multiple Changes
325 @subsection Making Multiple Changes
327 @cindex multiple changes to permissions
328 The format of symbolic modes is actually more complex than described
329 above (@pxref{Setting Permissions}). It provides two ways to make
330 multiple changes to files' permissions.
332 The first way is to specify multiple @var{operation} and
333 @var{permissions} parts after a @var{users} part in the symbolic mode.
335 For example, the mode:
342 gives users other than the owner of the file read permission and, if
343 it is a directory or if someone already had execute permission
344 to it, gives them execute permission; and it also denies them write
345 permission to it file. It does not affect the permission that the
346 owner of the file has for it. The above mode is equivalent to
354 The second way to make multiple changes is to specify more than one
355 simple symbolic mode, separated by commas. For example, the mode:
362 gives everyone permission to read the file and removes write
363 permission on it for all users except its owner. Another example:
370 sets all of the non-special permissions for the file explicitly. (It
371 gives users who are not in the file's group no permission at all for
374 The two methods can be combined. The mode:
381 gives all users permission to read the file, and gives users who are in
382 the file's group permission to execute it, as well, but not permission
383 to write to it. The above mode could be written in several different
390 @node Umask and Protection
391 @subsection The Umask and Protection
393 @cindex umask and modes
394 @cindex modes and umask
395 If the @var{users} part of a symbolic mode is omitted, it defaults to
396 @samp{a} (affect all users), except that any permissions that are
397 @emph{set} in the system variable @code{umask} are @emph{not affected}.
398 The value of @code{umask} can be set using the
399 @code{umask} command. Its default value varies from system to system.
401 @cindex giving away permissions
402 Omitting the @var{users} part of a symbolic mode is generally not useful
403 with operations other than @samp{+}. It is useful with @samp{+} because
404 it allows you to use @code{umask} as an easily customizable protection
405 against giving away more permission to files than you intended to.
407 As an example, if @code{umask} has the value 2, which removes write
408 permission for users who are not in the file's group, then the mode:
415 adds permission to write to the file to its owner and to other users who
416 are in the file's group, but @emph{not} to other users. In contrast,
424 ignores @code{umask}, and @emph{does} give write permission for
425 the file to all users.
428 @section Numeric Modes
430 @cindex numeric modes
431 @cindex file permissions, numeric
432 @cindex octal numbers for file modes
433 File permissions are stored internally as 16 bit integers. As an
434 alternative to giving a symbolic mode, you can give an octal (base 8)
435 number that corresponds to the internal representation of the new mode.
436 This number is always interpreted in octal; you do not have to add a
437 leading 0, as you do in C. Mode 0055 is the same as mode 55.
439 A numeric mode is usually shorter than the corresponding symbolic
440 mode, but it is limited in that it can not take into account a file's
441 previous permissions; it can only set them absolutely.
443 The permissions granted to the user, to other users in the file's group,
444 and to other users not in the file's group are each stored as three
445 bits, which are represented as one octal digit. The three special
446 permissions are also each stored as one bit, and they are as a group
447 represented as another octal digit. Here is how the bits are arranged
448 in the 16 bit integer, starting with the lowest valued bit:
451 Value in Corresponding
454 Other users not in the file's group:
459 Other users in the file's group:
470 1000 Save text image on swap device
471 2000 Set group ID on execution
472 4000 Set user ID on execution
475 For example, numeric mode 4755 corresponds to symbolic mode
476 @samp{u=rwxs,go=rx}, and numeric mode 664 corresponds to symbolic mode
477 @samp{ug=rw,o=r}. Numeric mode 0 corresponds to symbolic mode