0

I am a user of the root account on the server named A. And I also own the accounts of user1 and user2.

When I create a file or directory in the account of user1, I want the owner of the file to be user2.

Setting the group is possible by using the setuid: Setting default permissions for newly created files and sub-directories under a directory in Linux.

For the user account, is there any way?

Example. Make file - traditional way:

[user1@srv1 tmp]$ id
uid=4001(user1) gid=4001(user1) groups=4001(user1)

[user1@srv1 tmp]$ touch test_user1

[user1@srv1 tmp]$ ls -al test_user1
-rw-rw-r-- 1 user1 user1 0 2014-01-09 15:24 test_user1

Example. Make file - what I want:

[user1@srv1 tmp]$ id
uid=4001(user1) gid=4001(user1) groups=4001(user1)

[user1@srv1 tmp]$ touch test_user1

[user1@srv1 tmp]$ ls -al test_user1
-rw-rw-r-- 1 user2 user1 0 2014-01-09 15:24 test_user1

I do not wish to have to change the permissions of the file using the chown command.

1
  • You can use su or sudo to run the command as the user you want to be the owner of the file.
    – Jenny D
    Jan 9, 2014 at 9:35

3 Answers 3

2

If you are using capabilities (and RHEL does), you can give the user CAP_CHOWN.

See this answer:

Why can't a normal user `chown` a file?

1
sudo -u username touch file.name

or

su username -c touch filename
0

You can change the file's user/group properties:

chown user2:user1 test_user1

The syntax is: chown <user>:<group> <file or dir> to change the owner/owner group from a file or folder

1
  • I hope that the file is created, the Owner changed. without chown
    – user204865
    Jan 10, 2014 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy