source: trunk/coreutils/doc/perm.texi@ 2747

Last change on this file since 2747 was 2554, checked in by bird, 20 years ago

coretuils-5.94

File size: 15.2 KB
Line 
1Each file has a set of @dfn{permissions} that control the kinds of
2access that users have to that file. The permissions for a file are
3also called its @dfn{access mode}. They can be represented either in
4symbolic form or as an octal number.
5
6@menu
7* Mode Structure:: Structure of file permissions.
8* Symbolic Modes:: Mnemonic permissions representation.
9* Numeric Modes:: Permissions as octal numbers.
10@end menu
11
12@node Mode Structure
13@section Structure of File Permissions
14
15There are three kinds of permissions that a user can have for a file:
16
17@enumerate
18@item
19@cindex read permission
20permission to read the file. For directories, this means permission to
21list the contents of the directory.
22@item
23@cindex write permission
24permission to write to (change) the file. For directories, this means
25permission to create and remove files in the directory.
26@item
27@cindex execute permission
28permission to execute the file (run it as a program). For directories,
29this means permission to access files in the directory.
30@end enumerate
31
32There are three categories of users who may have different permissions
33to perform any of the above operations on a file:
34
35@enumerate
36@item
37the file's owner;
38@item
39other users who are in the file's group;
40@item
41everyone else.
42@end enumerate
43
44@cindex owner, default
45@cindex group owner, default
46Files are given an owner and group when they are created. Usually the
47owner is the current user and the group is the group of the directory
48the file is in, but this varies with the operating system, the
49file system the file is created on, and the way the file is created. You
50can change the owner and group of a file by using the @command{chown} and
51@command{chgrp} commands.
52
53In addition to the three sets of three permissions listed above, a
54file's permissions have three special components, which affect only
55executable files (programs) and, on some systems, directories:
56
57@enumerate
58@item
59@cindex setuid
60set the process's effective user ID to that of the file upon execution
61(called the @dfn{setuid bit}). No effect on directories.
62@item
63@cindex setgid
64set 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
66files created in the directory into the same group as the directory, no
67matter what group the user who creates them is in.
68@item
69@cindex sticky
70@cindex swap space, saving text image in
71@cindex text image, saving in swap space
72@cindex restricted deletion flag
73prevent users from removing or renaming a file in a directory
74unless they own the file or the directory; this is called the
75@dfn{restricted deletion flag} for the directory.
76For regular files on some systems, save the program's text image on the
77swap device so it will load more quickly when run; this is called the
78@dfn{sticky bit}.
79@end enumerate
80
81In addition to the permissions listed above, there may be file attributes
82specific to the file system, e.g: access control lists (ACLs), whether a
83file is compressed, whether a file can be modified (immutability), whether
84a file can be dumped. These are usually set using programs
85specific to the file system. For example:
86@c should probably say a lot more about ACLs... someday
87
88@table @asis
89@item ext2
90On @acronym{GNU} and @acronym{GNU}/Linux the file permissions
91(``attributes'') specific to
92the ext2 file system are set using @command{chattr}.
93
94@item FFS
95On FreeBSD the file permissions (``flags'') specific to the FFS
96file system are set using @command{chrflags}.
97@end table
98
99Although a file's permission ``bits'' allow an operation on that file,
100that operation may still fail, because:
101
102@itemize
103@item
104the file-system-specific permissions do not permit it;
105
106@item
107the file system is mounted as read-only.
108@end itemize
109
110For example, if the immutable attribute is set on a file,
111it cannot be modified, regardless of the fact that you
112may have just run @code{chmod a+w FILE}.
113
114@node Symbolic Modes
115@section Symbolic Modes
116
117@cindex symbolic modes
118@dfn{Symbolic modes} represent changes to files' permissions as
119operations on single-character symbols. They allow you to modify either
120all or selected parts of files' permissions, optionally based on
121their previous values, and perhaps on the current @code{umask} as well
122(@pxref{Umask and Protection}).
123
124The format of symbolic modes is:
125
126@example
127@r{[}ugoa@dots{}@r{][}+-=@r{]}@var{perms}@dots{}@r{[},@dots{}@r{]}
128@end example
129
130@noindent
131where @var{perms} is either zero or more letters from the set
132@samp{rwxXst}, or a single letter from the set @samp{ugo}.
133
134The following sections describe the operators and other details of
135symbolic modes.
136
137@menu
138* Setting Permissions:: Basic operations on permissions.
139* Copying Permissions:: Copying existing permissions.
140* Changing Special Permissions:: Special permissions.
141* Conditional Executability:: Conditionally affecting executability.
142* Multiple Changes:: Making multiple changes.
143* Umask and Protection:: The effect of the umask.
144@end menu
145
146@node Setting Permissions
147@subsection Setting Permissions
148
149The basic symbolic operations on a file's permissions are adding,
150removing, and setting the permission that certain users have to read,
151write, and execute the file. These operations have the following
152format:
153
154@example
155@var{users} @var{operation} @var{permissions}
156@end example
157
158@noindent
159The spaces between the three parts above are shown for readability only;
160symbolic modes cannot contain spaces.
161
162The @var{users} part tells which users' access to the file is changed.
163It consists of one or more of the following letters (or it can be empty;
164@pxref{Umask and Protection}, for a description of what happens then). When
165more than one of these letters is given, the order that they are in does
166not matter.
167
168@table @code
169@item u
170@cindex owner of file, permissions for
171the user who owns the file;
172@item g
173@cindex group, permissions for
174other users who are in the file's group;
175@item o
176@cindex other permissions
177all other users;
178@item a
179all users; the same as @samp{ugo}.
180@end table
181
182The @var{operation} part tells how to change the affected users' access
183to the file, and is one of the following symbols:
184
185@table @code
186@item +
187@cindex adding permissions
188to add the @var{permissions} to whatever permissions the @var{users}
189already have for the file;
190@item -
191@cindex removing permissions
192@cindex subtracting permissions
193to remove the @var{permissions} from whatever permissions the
194@var{users} already have for the file;
195@item =
196@cindex setting permissions
197to make the @var{permissions} the only permissions that the @var{users}
198have for the file.
199@end table
200
201The @var{permissions} part tells what kind of access to the file should
202be changed; it is normally zero or more of the following letters. As with the
203@var{users} part, the order does not matter when more than one letter is
204given. Omitting the @var{permissions} part is useful only with the
205@samp{=} operation, where it gives the specified @var{users} no access
206at all to the file.
207
208@table @code
209@item r
210@cindex read permission, symbolic
211the permission the @var{users} have to read the file;
212@item w
213@cindex write permission, symbolic
214the permission the @var{users} have to write to the file;
215@item x
216@cindex execute permission, symbolic
217the permission the @var{users} have to execute the file.
218@end table
219
220For example, to give everyone permission to read and write a file,
221but not to execute it, use:
222
223@example
224a=rw
225@end example
226
227To remove write permission for from all users other than the file's
228owner, use:
229
230@example
231go-w
232@end example
233
234@noindent
235The above command does not affect the access that the owner of
236the file has to it, nor does it affect whether other users can
237read or execute the file.
238
239To give everyone except a file's owner no permission to do anything with
240that file, use the mode below. Other users could still remove the file,
241if they have write permission on the directory it is in.
242
243@example
244go=
245@end example
246
247@noindent
248Another way to specify the same thing is:
249
250@example
251og-rwx
252@end example
253
254@node Copying Permissions
255@subsection Copying Existing Permissions
256
257@cindex copying existing permissions
258@cindex permissions, copying existing
259You can base a file's permissions on its existing permissions. To do
260this, instead of using a series of @samp{r}, @samp{w}, or @samp{x}
261letters after the
262operator, you use the letter @samp{u}, @samp{g}, or @samp{o}. For
263example, the mode
264
265@example
266o+g
267@end example
268
269@noindent
270adds the permissions for users who are in a file's group to the
271permissions that other users have for the file. Thus, if the file
272started out as mode 664 (@samp{rw-rw-r--}), the above mode would change
273it to mode 666 (@samp{rw-rw-rw-}). If the file had started out as mode
274741 (@samp{rwxr----x}), the above mode would change it to mode 745
275(@samp{rwxr--r-x}). The @samp{-} and @samp{=} operations work
276analogously.
277
278@node Changing Special Permissions
279@subsection Changing Special Permissions
280
281@cindex changing special permissions
282In addition to changing a file's read, write, and execute permissions,
283you can change its special permissions. @xref{Mode Structure}, for a
284summary of these permissions.
285
286To change a file's permission to set the user ID on execution, use
287@samp{u} in the @var{users} part of the symbolic mode and
288@samp{s} in the @var{permissions} part.
289
290To change a file's permission to set the group ID on execution, use
291@samp{g} in the @var{users} part of the symbolic mode and
292@samp{s} in the @var{permissions} part.
293
294To change a file's permission to set the restricted deletion flag or sticky bit,
295omit the @var{users} part of the symbolic mode (or use @samp{a}) and put
296@samp{t} in the @var{permissions} part.
297
298For example, to add set-user-ID permission to a program,
299you can use the mode:
300
301@example
302u+s
303@end example
304
305To remove both set-user-ID and set-group-ID permission from
306it, you can use the mode:
307
308@example
309ug-s
310@end example
311
312To set the restricted deletion flag or sticky bit, you can use
313the mode:
314
315@example
316+t
317@end example
318
319The combination @samp{o+s} has no effect. On @acronym{GNU} systems
320the combinations @samp{u+t} and @samp{g+t} have no effect, and
321@samp{o+t} acts like plain @samp{+t}.
322
323The @samp{=} operator is not very useful with special permissions; for
324example, the mode:
325
326@example
327o=t
328@end example
329
330@noindent
331does set the restricted deletion flag or sticky bit, but it also
332removes all read, write, and execute permissions that users not in the
333file's group might have had for it.
334
335@node Conditional Executability
336@subsection Conditional Executability
337
338@cindex conditional executability
339There is one more special type of symbolic permission: if you use
340@samp{X} instead of @samp{x}, execute permission is affected only if the
341file is a directory or already had execute permission.
342
343For example, this mode:
344
345@example
346a+X
347@end example
348
349@noindent
350gives all users permission to search directories, or to execute files if
351anyone could execute them before.
352
353@node Multiple Changes
354@subsection Making Multiple Changes
355
356@cindex multiple changes to permissions
357The format of symbolic modes is actually more complex than described
358above (@pxref{Setting Permissions}). It provides two ways to make
359multiple changes to files' permissions.
360
361The first way is to specify multiple @var{operation} and
362@var{permissions} parts after a @var{users} part in the symbolic mode.
363
364For example, the mode:
365
366@example
367og+rX-w
368@end example
369
370@noindent
371gives users other than the owner of the file read permission and, if
372it is a directory or if someone already had execute permission
373to it, gives them execute permission; and it also denies them write
374permission to the file. It does not affect the permission that the
375owner of the file has for it. The above mode is equivalent to
376the two modes:
377
378@example
379og+rX
380og-w
381@end example
382
383The second way to make multiple changes is to specify more than one
384simple symbolic mode, separated by commas. For example, the mode:
385
386@example
387a+r,go-w
388@end example
389
390@noindent
391gives everyone permission to read the file and removes write
392permission on it for all users except its owner. Another example:
393
394@example
395u=rwx,g=rx,o=
396@end example
397
398@noindent
399sets all of the non-special permissions for the file explicitly. (It
400gives users who are not in the file's group no permission at all for
401it.)
402
403The two methods can be combined. The mode:
404
405@example
406a+r,g+x-w
407@end example
408
409@noindent
410gives all users permission to read the file, and gives users who are in
411the file's group permission to execute it, as well, but not permission
412to write to it. The above mode could be written in several different
413ways; another is:
414
415@example
416u+r,g+rx,o+r,g-w
417@end example
418
419@node Umask and Protection
420@subsection The Umask and Protection
421
422@cindex umask and modes
423@cindex modes and umask
424If the @var{users} part of a symbolic mode is omitted, it defaults to
425@samp{a} (affect all users), except that any permissions that are
426@emph{set} in the system variable @code{umask} are @emph{not affected}.
427The value of @code{umask} can be set using the
428@code{umask} command. Its default value varies from system to system.
429
430@cindex giving away permissions
431Omitting the @var{users} part of a symbolic mode is generally not useful
432with operations other than @samp{+}. It is useful with @samp{+} because
433it allows you to use @code{umask} as an easily customizable protection
434against giving away more permission to files than you intended to.
435
436As an example, if @code{umask} has the value 2, which removes write
437permission for users who are not in the file's group, then the mode:
438
439@example
440+w
441@end example
442
443@noindent
444adds permission to write to the file to its owner and to other users who
445are in the file's group, but @emph{not} to other users. In contrast,
446the mode:
447
448@example
449a+w
450@end example
451
452@noindent
453ignores @code{umask}, and @emph{does} give write permission for
454the file to all users.
455
456@node Numeric Modes
457@section Numeric Modes
458
459@cindex numeric modes
460@cindex file permissions, numeric
461@cindex octal numbers for file modes
462As an
463alternative to giving a symbolic mode, you can give an octal (base 8)
464number that represents the new mode.
465This number is always interpreted in octal; you do not have to add a
466leading 0, as you do in C. Mode 0055 is the same as mode 55.
467
468A numeric mode is usually shorter than the corresponding symbolic
469mode, but it is limited in that it cannot take into account a file's
470previous permissions; it can only set them absolutely.
471
472The permissions granted to the user,
473to other users in the file's group,
474and to other users not in the file's group each require three
475bits, which are represented as one octal digit. The three special
476permissions also require one bit each, and they are as a group
477represented as another octal digit. Here is how the bits are arranged,
478starting with the lowest valued bit:
479
480@example
481Value in Corresponding
482Mode Permission
483
484 Other users not in the file's group:
485 1 Execute
486 2 Write
487 4 Read
488
489 Other users in the file's group:
490 10 Execute
491 20 Write
492 40 Read
493
494 The file's owner:
495 100 Execute
496 200 Write
497 400 Read
498
499 Special permissions:
5001000 Restricted deletion flag or sticky bit
5012000 Set group ID on execution
5024000 Set user ID on execution
503@end example
504
505For example, numeric mode 4755 corresponds to symbolic mode
506@samp{u=rwxs,go=rx}, and numeric mode 664 corresponds to symbolic mode
507@samp{ug=rw,o=r}. Numeric mode 0 corresponds to symbolic mode
508@samp{a=}.
Note: See TracBrowser for help on using the repository browser.