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

DESCRIPTION

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

RETURN VALUE

51       On  success,  zero is returned.  On error, -1 is returned, and errno is
52       set appropriately.
53

ERRORS

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