changing ownership of file as group user
Only the owner of a file or root is permitted to change permissions.
And even if a file is owned by you, you can't change it ownership to another user. You can however, change its group, to one of the groups which your user is part of.
If a user can execute sudo
then the user can execute:
sudo chown new-owner filename
You can try to manipulate the system files in a way it will be possible, however it will create major security risk to your system.
Such non recommended solution might be:
sudo cp /bin/chown /bin/chown.mod sudo chown root.www-data /bin/chown.mod sudo chmod 750 /bin/chown.mod sudo chmod +s /bin/chown.mod
Now, user with groupid www-data can execute
/bin/chown.mod
as userroot
/bin/chown.mod userid /path/to/filename
It is very dangerous, for example: as such user can change the owner of /etc/passwd to himself, modify the password file, and change the owner back to root, and a new user was added to the system.
Related videos on Youtube
![Toskan](https://i.stack.imgur.com/7hsON.png?s=256&g=1)
Toskan
Updated on September 18, 2022Comments
-
Toskan almost 2 years
let's say i have files owned by:
sftp-user:www-data
now I want that www-data can change the ownership of it, say to foobar. Is that even possible?
-
M. Becerra over 7 yearsPossible duplicate of www-data ownership
-
Yaron over 7 yearsdo you want someone with
groupid www-data
to be able to change the owner of files owned by another user? -
Toskan over 7 years@Yaron yes exactly
-
Toskan over 7 yearse.g. is it possible if a file owned by sftp-user and group www-data that someone of the group www-data can change the file ownership?
-
-
Jeremy over 6 yearsIs the rationale for this restriction (in particular, that members of the owning group are not permitted to change permissions) explained anywhere?