The chown
command is only available for root
, for security reasons, so if you want to do that, you'll have to do it as root.
There are 2 things that come to my mind that you can do:
Use the
SETUID
bit. This way, you're allowing users to run the script asroot
(though it also has security concerns, depending on what your script does). More on this here.You might also create a task-based queue (for example, using redis). The script would insert a value on the queue when run, and a script run as
root
would read that queue and make any needed changes (in your case, usechown
on that file).