Note: Please feel free to edit the question -- I am having a hard time expressing it!
Question:
How do you impersonate a regular user--while still retaining admin/root privileges to execute any command on behalf of that target user?
A Mechanism To:
- Allows Complete root/admin access to execute any command;
- Allows you to specify some "Target Group";
- Allow you to specify some "Target User";
- And ensures that all commands, scripts, etc, are executed on behalf of that user/group -- setting the "Target User" and "Target Group" as owner ...
These examples show how pkexec and/or sudo have to be specified for each and every command -- which is what I am trying to avoid doing :
pkexec:
FAIL: Requires admin to prefix with sudo and pkexec.
sudo pkexec -u TestUser mkdir /home/TestUser/NewFolder- Success: Creates folder and assigns correct permissions
sudo pkexec -u btsync mkdir /opt/btsync- FAIL: Does not work for service accounts without home folders:
Error changing to home directory /home/btsync: No such file or directory
- FAIL: Does not work for service accounts without home folders:
sudo:
FAIL: Requires admin to prefix with sudo.
1 sudo pkexec -u btsync mkdir /opt/btsync
- FAIL: Makes Folder - But Assigns Root Owner.
- FAIL: Requires fixing permissions afterwards, increasing commands entered by x3 sometimes.
Desired Functionally using BTSync as an Example:
root@localhost > enterElevatedShell -u btsyncbtsync@localhost > nano /etc/asound.conf- many commands entered manually.
btsync@localhost > exitroot@localhost >
or:
root@localhost > stopauthorizationModulesroot@localhost > sudo -i btsyncbtsync@localhost > nano /etc/asound.conf- many commands entered manually.
btsync@localhost > exitroot@localhost >
or:
root@localhost > sudo --setUmask=0222 --setTargetUser=btsyncroot@localhost > sudo -E mkdir /opt/btsync
Common Scenarios:
Note: This is in the context of manual system administration.
With Root Access:
- Create /home/[username]/Subfolder | w/[username] as owner
- Create /opt/[serviceAccount]Service | w/[serviceAccount] as owener
- Create/Modify /etc/service/[someconfig] | w /[serviceAccount] as owner
Generally, I execute many, many commands, and going back behind flipping permission bits is tedious, non-consistent, and a security vulnerability rising from admin forgetfulness, or type-os.