1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\" and Copyright (C) 2006, 2014 Michael Kerrisk
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1997-01-12 by Michael Haardt
29 .\" <michael@cantor.informatik.rwth-aachen.de>: NFS details
30 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .TH CHMOD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
34 chmod, fchmod, fchmodat \- change permissions of a file
37 .B #include <sys/stat.h>
39 .BI "int chmod(const char *" pathname ", mode_t " mode );
41 .BI "int fchmod(int " fd ", mode_t " mode );
43 .BR "#include <fcntl.h>" " /* Definition of AT_* constants */"
44 .B #include <sys/stat.h>
46 .BI "int fchmodat(int " dirfd ", const char *" pathname ", mode_t " \
47 mode ", int " flags );
51 Feature Test Macro Requirements for glibc (see
52 .BR feature_test_macros (7)):
60 _POSIX_C_SOURCE\ >=\ 199309L
61 .\" || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED)
67 _BSD_SOURCE || _POSIX_C_SOURCE
70 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
71 _POSIX_C_SOURCE >= 200809L
73 Glibc 2.11 and earlier:
74 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
75 .\" || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED)
85 _POSIX_C_SOURCE\ >=\ 200809L
98 system calls change a files mode bits.
99 (The file mode consists of the file permission bits plus the set-user-ID,
100 set-group-ID, and sticky bits.)
101 These system calls differ only in how the file is specified:
104 changes the mode of the file specified whose pathname is given in
106 which is dereferenced if it is a symbolic link.
109 changes the mode of the file referred to by the open file descriptor
112 The new file mode is specified in
114 which is a bit mask created by ORing together zero or
115 more of the following:
117 .BR S_ISUID " (04000)"
118 set-user-ID (set process effective user ID on
121 .BR S_ISGID " (02000)"
122 set-group-ID (set process effective group ID on
124 mandatory locking, as described in
126 take a new file's group from parent directory, as described in
131 .BR S_ISVTX " (01000)"
132 sticky bit (restricted deletion flag, as described in
135 .BR S_IRUSR " (00400)"
138 .BR S_IWUSR " (00200)"
141 .BR S_IXUSR " (00100)"
142 execute/search by owner ("search" applies for directories,
143 and means that entries within the directory can be accessed)
145 .BR S_IRGRP " (00040)"
148 .BR S_IWGRP " (00020)"
151 .BR S_IXGRP " (00010)"
152 execute/search by group
154 .BR S_IROTH " (00004)"
157 .BR S_IWOTH " (00002)"
160 .BR S_IXOTH " (00001)"
161 execute/search by others
163 The effective UID of the calling process must match the owner of the file,
164 or the process must be privileged (Linux: it must have the
168 If the calling process is not privileged (Linux: does not have the
170 capability), and the group of the file does not match
171 the effective group ID of the process or one of its
172 supplementary group IDs, the
174 bit will be turned off,
175 but this will not cause an error to be returned.
177 As a security measure, depending on the filesystem,
178 the set-user-ID and set-group-ID execution bits
179 may be turned off if a file is written.
180 (On Linux, this occurs if the writing process does not have the
183 On some filesystems, only the superuser can set the sticky bit,
184 which may have a special meaning.
185 For the sticky bit, and for set-user-ID and set-group-ID bits on
189 On NFS filesystems, restricting the permissions will immediately influence
190 already open files, because the access control is done on the server, but
191 open files are maintained by the client.
192 Widening the permissions may be
193 delayed for other clients if attribute caching is enabled on them.
199 system call operates in exactly the same way as
201 except for the differences described here.
203 If the pathname given in
205 is relative, then it is interpreted relative to the directory
206 referred to by the file descriptor
208 (rather than relative to the current working directory of
209 the calling process, as is done by
211 for a relative pathname).
221 is interpreted relative to the current working
222 directory of the calling process (like
232 can either be 0, or include the following flag:
234 .B AT_SYMLINK_NOFOLLOW
237 is a symbolic link, do not dereference it:
238 instead operate on the link itself.
239 This flag is not currently implemented.
243 for an explanation of the need for
246 On success, zero is returned.
247 On error, \-1 is returned, and
249 is set appropriately.
251 Depending on the filesystem,
252 errors other than those listed below can be returned.
254 The more general errors for
259 Search permission is denied on a component of the path prefix.
261 .BR path_resolution (7).)
265 points outside your accessible address space.
268 An I/O error occurred.
271 Too many symbolic links were encountered in resolving
279 The file does not exist.
282 Insufficient kernel memory was available.
285 A component of the path prefix is not a directory.
288 The effective UID does not match the owner of the file,
289 and the process is not privileged (Linux: it does not have the
294 The file is marked immutable or append-only.
296 .BR ioctl_iflags (2).)
299 The named file resides on a read-only filesystem.
301 The general errors for
319 The same errors that occur for
323 The following additional errors can occur for
328 is not a valid file descriptor.
331 Invalid flag specified in
338 is a file descriptor referring to a file other than a directory.
343 .BR AT_SYMLINK_NOFOLLOW ,
344 which is not supported.
347 was added to Linux in kernel 2.6.16;
348 library support was added to glibc in version 2.4.
352 4.4BSD, SVr4, POSIX.1-2001i, POSIX.1-2008.
357 .SS C library/kernel differences
360 wrapper function implements the POSIX-specified
361 interface described in this page.
362 This interface differs from the underlying Linux system call, which does
368 On older kernels where
370 is unavailable, the glibc wrapper function falls back to the use of
374 is a relative pathname,
375 glibc constructs a pathname based on the symbolic link in
377 that corresponds to the
387 .BR path_resolution (7),