6

I am on slackware64 v14.0 and I have file that belongs to me:

-rwxrwxr-x+   1 nass  shares    137934 Mar  7 00:06 myfile.csv*

I am a member of the "shares" group. The folder that contains myfile looks like this

drwxrwsr-x+  12 nass shares 4096 Mar 12 04:54 winmx/

I now want to give ownership of this file to another user of this pc. The other user is also a member of the shares group. However,

chown otheruser myfile.csv   

does not do the trick. I get a

chown: changing ownership of 'myfile.csv': Operation not permitted

I had recently asked a similar question about gid, but this is not the same problem. How can I solve this ?

nass
  • 1,458

1 Answers1

11

You (as a regular user) can't "give away" your files. Root, however, can do it.

vonbrand
  • 18,253
  • 1
    The ability for a non-root user to "give away" files can actually be configured per filesystem, at least on some OSs. But giving non-root users that ability can open security holes, so it's usually disabled. – Keith Thompson Mar 12 '14 at 00:36
  • @KeithThompson, never seen such on any Unixy system. Care to expand? – vonbrand Mar 12 '14 at 00:42
  • 2
    I've seen it on a UNIX system some years ago; I don't remember the exact details off the top of my head, but I think it was an Alpha OSF1 system. See man pathconf; calling it with _PC_CHOWN_RESTRICTED tells you whether chown is restricted to root for the given path. (I don't think Linux lets you remove that restriction.) – Keith Thompson Mar 12 '14 at 00:52
  • @KeithThompson, as I remembered. The chown(2) system call may only be invoked by a privileged process (in Linux' case, one which has CAP_CHOWN, in general only root). AFAIU from pathconf(3) and chown(2), it is possible to restrict that rootly power for some files, not to relax it. – vonbrand Mar 12 '14 at 01:14
  • 1
    POSIX: "[EPERM] The effective user ID does not match the owner of the file, or the calling process does not have appropriate privileges and POSIX_CHOWN_RESTRICTED indicates that such privilege is required." – Keith Thompson Mar 12 '14 at 01:17
  • I am able to give away my files on an NFS partition mounted from a Netapp SAN today. It really kind of freaks me out because I thought the kernel managed permissioning, but anyway I am able to do it (so it shouldn't matter where I mount from). And the capabilities of my shell thread are all 0000... so I don't have some sort of CAP_CHOWN turned on... I don't think. (I can't chown in /tmp, for example). – Mike S Oct 23 '17 at 17:30