1CHMOD(2) Linux Programmer's Manual CHMOD(2)
2
3
4
6 chmod, fchmod - change permissions of a file
7
9 #include <sys/stat.h>
10
11 int chmod(const char *path, mode_t mode);
12 int fchmod(int fd, mode_t mode);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 fchmod(): _BSD_SOURCE || _XOPEN_SOURCE >= 500
17
19 These system calls change the permissions of a file. They differ only
20 in how the file is specified:
21
22 * chmod() changes the permissions of the file specified whose pathname
23 is given in path, which is dereferenced if it is a symbolic link.
24
25 * fchmod() changes the permissions of the file referred to by the open
26 file descriptor fd.
27
28 The new file permissions are specified in mode, which is a bit mask
29 created by ORing together zero or more of the following:
30
31 S_ISUID [22m(04000) set-user-ID (set process effective user ID on
32 execve(2))
33
34 S_ISGID [22m(02000) set-group-ID (set process effective group ID on
35 execve(2); mandatory locking, as described in
36 fcntl(2); take a new file's group from parent direc‐
37 tory, as described in chown(2) and mkdir(2))
38
39 S_ISVTX [22m(01000) sticky bit (restricted deletion flag, as described in
40 unlink(2))
41
42 S_IRUSR [22m(00400) read by owner
43
44 S_IWUSR [22m(00200) write by owner
45
46 S_IXUSR [22m(00100) execute/search by owner ("search" applies for direc‐
47 tories, and means that entries within the directory
48 can be accessed)
49
50 S_IRGRP [22m(00040) read by group
51
52 S_IWGRP [22m(00020) write by group
53
54 S_IXGRP [22m(00010) execute/search by group
55
56 S_IROTH [22m(00004) read by others
57
58 S_IWOTH [22m(00002) write by others
59
60 S_IXOTH [22m(00001) execute/search by others
61
62 The effective UID of the calling process must match the owner of the
63 file, or the process must be privileged (Linux: it must have the
64 CAP_FOWNER capability).
65
66 If the calling process is not privileged (Linux: does not have the
67 CAP_FSETID capability), and the group of the file does not match the
68 effective group ID of the process or one of its supplementary group
69 IDs, the S_ISGID bit will be turned off, but this will not cause an
70 error to be returned.
71
72 As a security measure, depending on the file system, the set-user-ID
73 and set-group-ID execution bits may be turned off if a file is written.
74 (On Linux this occurs if the writing process does not have the
75 CAP_FSETID capability.) On some file systems, only the superuser can
76 set the sticky bit, which may have a special meaning. For the sticky
77 bit, and for set-user-ID and set-group-ID bits on directories, see
78 stat(2).
79
80 On N