I am logged in as root and want to execute a Bash script with sudo permissions as another user.
This is the test Bash script in /home/me/sudo.bash
:
mkdir -p /etc/test # Creating an /etc directory to test permissions
echo "test $(whoami) $USER $HOME" > /etc/test/a.txt
The command I currently have (run from root, run for me):
sudo --non-interactive --login --set-home --user=me \
sudo --non-interactive bash /home/me/sudo.bash
Contents of /etc/test/a.txt
:
test root root /home/me
What I expected:
test me me /home/me
What am I doing wrong here?
sudo
in that runs the given command asme
, that command being anothersudo
, which runs the given command asroot
, which isbash
with your shell script. What did you expect from the secondsudo
?sudo
is for switching the user tome
, the secondsudo
is for running the Bash script with elevated permissions, so I can create a directory in/etc
.me
androot
at the same time?me
, then useme
to modify the content.