1CHMOD(2)                   Linux Programmer's Manual                  CHMOD(2)
2
3
4

NAME

6       chmod, fchmod - change permissions of a file
7

SYNOPSIS

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():
17           _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
18           _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
19           || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
20

DESCRIPTION

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