Sometimes a command I'm executing needs to access a directory that's owned by root, e.g.
npm install -g ... might put a symlink in
I don't wish to run the command using
sudo because then every file it has touched will be owned by root (e.g. if you try
sudo touch tmp then issue
ll you'll see it's owned by root and in root group), but I still want to give it access to
Currently I temporarily change the ownership of the directory to
(whoami) and then changing it back to
Is there a way that linux can allow me same access as
root but the files touched/written are given ownership under the current user? e.g. by using a command
idk npm install -g .... Where
idk is something other than
Note that this question isn't about the specific example / use case of
/usr/bin/local. As any linux user is well aware, you could change directory permissions permanently so that permissions issue doesn't arise anymore.
The question is about ability to do this on a command by command basis (like
sudo gives root permissions on a command by command basis).
Linux permissions have the model "x user can do p", and sudo lets you say "let user x behave as if they were user y". I'm asking if there is a way to say "let user x behave as if they were y, but keep a note of the fact that it's really x and not y".