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 (https://stackoverflow.com/questions/580584/setting-default-permissions-for-newly-created-files-and-sub-directories-under-a)

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.

migrated from serverfault.com Jan 10 '14 at 16:54

This question came from our site for system and network administrators.

  • 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 '14 at 9:35
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

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

Your Answer

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