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

NAME

6       chown, fchown, lchown, fchownat - change ownership of a file
7

SYNOPSIS

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 versions <= 2.19: */ _BSD_SOURCE
27       fchownat():
28           Since glibc 2.10:
29               _POSIX_C_SOURCE >= 200809L
30           Before glibc 2.10:
31               _ATFILE_SOURCE
32

DESCRIPTION

34       These  system calls change the owner and group of a file.  The chown(),
35       fchown(), and lchown() system calls differ only  in  how  the  file  is
36       specified:
37
38       * chown()  changes  the  ownership  of  the file specified by pathname,
39         which is dereferenced if it is a symbolic link.
40
41       * fchown() changes the ownership of the file referred to  by  the  open
42         file descriptor fd.
43
44       * lchown() is like chown(), but does not dereference symbolic links.
45
46       Only  a  privileged  process (Linux: one with the CAP_CHOWN capability)
47       may change the owner of a file.  The owner of a  file  may  change  the
48       group  of  the  file  to  any group of which that owner is a member.  A
49       privileged process (Linux: with CAP_CHOWN) may change the  group  arbi‐
50       trarily.
51
52       If the owner or group is specified as -1, then that ID is not changed.
53
54       When the owner or group of an executable file is changed by an unprivi‐
55       leged user, the S_ISUID and S_ISGID mode bits are cleared.  POSIX  does
56       not specify whether this also should happen when root does the chown();
57       the Linux behavior depends on  the  kernel  version,  and  since  Linux
58       2.2.13,  root is treated like other users.  In case of a non-group-exe‐
59       cutable file (i.e., one for which the  S_IXGRP  bit  is  not  set)  the
60       S_ISGID  bit  indicates  mandatory  locking,  and  is  not cleared by a
61       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 va