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

NAME

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

SYNOPSIS

9       #include <unistd.h>
10
11       int chown(const char *path, uid_t owner, gid_t group);
12       int fchown(int fd, uid_t owner, gid_t group);
13       int lchown(const char *path, uid_t owner, gid_t group);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       fchown(), lchown(): _BSD_SOURCE || _XOPEN_SOURCE >= 500
18

DESCRIPTION

20       These  system  calls  change the owner and group of a file.  The differ
21       only in how the file is specified:
22
23       * chown() changes the ownership of the file specified by path, which is
24         dereferenced if it is a symbolic link.
25
26       * fchown()  changes  the  ownership of the file referred to by the open
27         file descriptor fd.
28
29       * lchown() is like chown(), but does not dereference symbolic links.
30
31       Only a privileged process (Linux: one with  the  CAP_CHOWN  capability)
32       may  change  the  owner  of a file.  The owner of a file may change the
33       group of the file to any group of which that  owner  is  a  member.   A
34       privileged  process  (Linux: with CAP_CHOWN) may change the group arbi‐
35       trarily.
36
37       If the owner or group is specified as -1, then that ID is not changed.
38
39       When the owner or group of an executable file are changed by an unpriv‐
40       ileged  user the S_ISUID and S_ISGID mode bits are cleared.  POSIX does
41       not specify whether this also should happen when root does the chown();
42       the  Linux  behavior  depends on the kernel version.  In case of a non-
43       group-executable file (i.e., one for which the S_IXGRP bit is not  set)
44       the  S_ISGID  bit  indicates mandatory locking, and is not cleared by a
45       chown().
46

RETURN VALUE

48       On success, zero is returned.  On error, -1 is returned, and  errno  is
49       set appropriately.
50

ERRORS

52       Depending  on  the file system, other errors can be returned.  The more
53       general errors for chown() are listed below.
54
55       EACCES Search permission is denied on a component of the  path  prefix.
56              (See also path_resolution(7).)
57
58       EFAULT path points outside your accessible address space.
59
60       ELOOP  Too many symbolic links were encountered in resolving path.
61
62       ENAMETOOLONG
63              path is too long.
64
65       ENOENT The file does not exist.
66
67       ENOMEM Insufficient kernel memory was available.
68
69       ENOTDIR
70              A component of the path prefix is not a directory.
71
72       EPERM  The  calling  process did not have the required permissions (see
73              above) to change owner and/or group.
74
75       EROFS  The named file resides on a