Automatically execute bash script under the privileges of another user
So did I get that right.
User "bla" wants to run a command as User "blub" ?
Then something like this could work:
sudo -u blub /path/to/command
If you need this to be done without being asked for a password add the follwing line to /etc/sudoers (via visudo command):
bla ALL=(blub) NOPASSWD: /path/to/command
you can work with SUID and SGID bit permissions (note that this may be really dangerous)
give the permissions to execute this file to a group that the user you are executing the script as belong to, and set via SUID anyone who runs this script to run it as the user who owns the script
sudo chmod 4751 /path/to/my/file
sudo chgrp somegroup /path/to/my/file
Then, you just need to execute the script as userB who is member of somegroup and it will be executed with as userA and somegroup
ls -l /path/to/my/file
-rwsr-xr-- userA somegroup /path/to/my/file