How do I grant a specific user the right to change user and group ownership of files and directories inside a specific directory?
I did a Google search and saw that there is such a thing as setfacl
, which allows for granting users specific rights to change permissions for files and directories. From what I read, though, this command does not allow granting chown permissions.
So, say a file has
user1 user1 theFile1
user1 user1 theDirectory1
Issuing the following command would fail.
[user1@THEcomputer]$ chown user2 theFile
I do have root access on the computer. Is there a way to grant a user to issue chown
commands inside a directory?
UPDATE: How to add a user to a group.
Here is the article that I used to add datamover
to the hts
group.
[root@Venus ~]# usermod -a -G datamover hts
[root@Venus ~]# exit
logout
[hts@Venus Receive]$ groups
hts wireshark datamover
[hts@Venus Receive]$
UPDATE (address comment by RuiFRibeiro):
Changing the ownership of the directory to the directory does not work, see screenshot.
[datamover@Venus root]$ ls -la
total 311514624
drwxrwxrwx. 6 datamover datamover 4096 Oct 14 14:05 .
drwxr-xr-x 4 root root 4096 Aug 20 16:52 ..
-rwxrwxrwx. 1 datamover datamover 674 Aug 31 16:47 create_files.zip
drwxrwxrwx 2 datamover datamover 4096 Oct 17 17:07 dudi
-rwxrwxrwx. 1 datamover datamover 318724299315 Oct 13 15:47 Jmr400.mov
-rwxrwxrwx. 1 datamover datamover 182693854 Aug 31 16:47 Jmr_Commercial_WithSubtitles.mov
-rwxrwxrwx. 1 datamover datamover 80607864 Aug 31 16:47 Jmr_DataMover_Final.mov
drwxrwxrwx. 2 datamover datamover 122880 Aug 23 11:54 ManyFiles
drwxrwxrwx. 3 datamover datamover 4096 Oct 25 07:18 Receive
drwxrwxrwx 2 datamover datamover 4096 Oct 14 13:40 sarah
-rwxrwxrwx 1 datamover datamover 3184449 Oct 14 14:05 SourceGrid_4_40_bin.zip
[datamover@Venus root]$ cd ./Receive/
[datamover@Venus Receive]$ ls -la
total 178540
drwxrwxrwx. 3 datamover datamover 4096 Oct 25 07:18 .
drwxrwxrwx. 6 datamover datamover 4096 Oct 14 14:05 ..
-rwxrwxrwx 1 hts hts 182693854 Oct 25 07:18 Jmr_Commercial_WithSubtitles.mov
drwxrwxrwx 2 datamover datamover 122880 Oct 23 13:33 ManyFiles
[datamover@Venus Receive]$ chown datamover:datamover ./Jmr_Commercial_WithSubtitles.mov
chown: changing ownership of './Jmr_Commercial_WithSubtitles.mov': Operation not permitted
Here is an attempt as the owner of the file:
[hts@Venus Receive]$ chown datamover:datamover Jmr_Commercial_WithSubtitles.mov
chown: changing ownership of 'Jmr_Commercial_WithSubtitles.mov': Operation not permitted
So as you can see, neither possibility works.
UPDATE (address countermode's answer)
Group ownership may be changed by the file owner (and root). However, this is restricted to the groups the owner belongs to.
Yes, one does have to log out first. Here is the result of my attempt:
[hts@Venus ~]$ groups hts
hts : hts wireshark datamover
[hts@Venus ~]$ cd /mnt/DataMover/root/Receive/
[hts@Venus Receive]$ ls -la
total 178540
drwxrwxrwx. 3 datamover datamover 4096 Oct 25 07:18 .
drwxrwxrwx. 6 datamover datamover 4096 Oct 14 14:05 ..
-rwxrwxrwx 1 hts hts 182693854 Oct 25 07:18 Jmr_Commercial_WithSubtitles.mov
drwxrwxrwx 2 datamover datamover 122880 Oct 23 13:33 ManyFiles
[hts@Venus Receive]$ chown hts:datamover ./Jmr_Commercial_WithSubtitles.mov
[hts@Venus Receive]$ ls -la
total 178540
drwxrwxrwx. 3 datamover datamover 4096 Oct 25 07:18 .
drwxrwxrwx. 6 datamover datamover 4096 Oct 14 14:05 ..
-rwxrwxrwx 1 hts datamover 182693854 Oct 25 07:18 Jmr_Commercial_WithSubtitles.mov
drwxrwxrwx 2 datamover datamover 122880 Oct 23 13:33 ManyFiles
[hts@Venus Receive]$ chown datamover:datamover ./Jmr_Commercial_WithSubtitles.mov
chown: changing ownership of ‘./Jmr_Commercial_WithSubtitles.mov’: Operation not permitted
[hts@Venus Receive]$
Adding hts to the datamover group does indeed allow me to change the ownership of the group part, so now a partial answer and validation for the statement.