1CHOWN(2) Linux Programmer's Manual CHOWN(2)
2
3
4
6 chown, fchown, lchown, fchownat - change ownership of a file
7
9 #include <unistd.h>
10
11 int chown(const char *pathname, uid_t owner, gid_t group);
12 int fchown(int fd, uid_t owner, gid_t group);
13 int lchown(const char *pathname, uid_t owner, gid_t group);
14
15 #include <fcntl.h> /* Definition of AT_* constants */
16 #include <unistd.h>
17
18 int fchownat(int dirfd, const char *pathname,
19 uid_t owner, gid_t group, int flags);
20
21 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23 fchown(), lchown():
24 /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
25 || _XOPEN_SOURCE >= 500
26 || /* Glibc <= 2.19: */ _BSD_SOURCE
27
28 fchownat():
29 Since glibc 2.10:
30 _POSIX_C_SOURCE >= 200809L
31 Before glibc 2.10:
32 _ATFILE_SOURCE
33
35 These system calls change the owner and group of a file. The chown(),
36 fchown(), and lchown() system calls differ only in how the file is
37 specified:
38
39 * chown() changes the ownership of the file specified by pathname,
40 which is dereferenced if it is a symbolic link.
41
42 * fchown() changes the ownership of the file referred to by the open
43 file descriptor fd.
44
45 * lchown() is like chown(), but does not dereference symbolic links.
46
47 Only a privileged process (Linux: one with the CAP_CHOWN capability)
48 may change the owner of a file. The owner of a file may change the
49 group of the file to any group of which that owner is a member. A
50 privileged process (Linux: with CAP_CHOWN) may change the group arbi‐
51 trarily.
52
53 If the owner or group is specified as -1, then that ID is not changed.
54
55 When the owner or group of an executable file is changed by an unprivi‐
56 leged user, the S_ISUID and S_ISGID mode bits are cleared. POSIX does
57 not specify whether this also should happen when root does the chown();
58 the Linux behavior depends on the kernel version, and since Linux
59 2.2.13, root is treated like other users. In case of a non-group-exe‐
60 cutable file (i.e., one for which the S_IXGRP bit is not set) the S_IS‐
61 GID bit indicates mandatory locking, and is not cleared by a chown().
62
63 When the owner or group of an executable file is changed (by any user),
64 all capability sets for the file are cleared.
65
66 fchownat()
67 The fchownat() system call operates in exactly the same way as chown(),
68 except for the differences described here.
69
70 If the pathname given in pathname is relative, then it is interpreted
71 relative to the directory referred to by the file descriptor dirfd
72 (rather than relative to the current working directory of the calling
73 process, as is done by chown() for a relative pathname).
74
75 If pathname is relative and dirfd is the special value AT_