Reputation: 1789
I have to call two commands, the first one is turning on vpn which needs root, the other one is rpmbuild
which don't want to work on root due to security vulnerabilities. I want to cheat and fake non-root user to call rpmbuild
. I don't think i would run into security troubles running it under docker in CI, so i want to neglect that
I cannot do
USER user
...
USER root
because all commands run during runtime and in the single script, so i had to manage both paths for default user directories like /home/user
and /root
Upvotes: 1
Views: 284
Reputation: 2318
To run a specific command in the script as non-root user, you can use the command su - user -c "<command>"
. After the command specified in -c
argument is executed, it will go back to run the next commands as root user to turn on the VPN
su - user -c "rpmbuild ..." # Run rmpbuild as non-root user
# Turning on VPN as root below
...
Upvotes: 2