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.

3 Answers3

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?

Bandrami
  • 850
1
sudo -u username touch file.name

or

su username -c touch filename
Anthon
  • 79,293
APZ
  • 111
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

jofel
  • 26,758
vs06
  • 111