Search code examples
linuxamazon-ec2rundeck

rundeck - switch to root user in job script


Logging via terminal I can switch to root user fine:

ubuntu@ip-10-0-0-70:~$ sudo -s
root@ip-10-0-0-70:~# whoami
root

So I created in rundeck a job script with this:

whoami;
echo "1st step";
sudo -s;
echo "2nd step";

And when I run this, it prints:

ubuntu
1st step

After print '1st step' it get stucked forever. Seems a problem with sudo -s command.

  • tried sudo -i but the same happens
  • tried sudo su - root but the same happens
  • rundeck is logging as ubuntu user, me too

any idea to switch to root in rundeck script?


Solution

  • This is the expected behaviour. You are running a shell via 'sudo -s' and then not leaving/exiting it ! So it waits forever for somethig that won't come.

    You can probably add 'sudo' as an Advanced option of your script (where it says "Run script with an interpreter or prefix. E.g.: sudo, time:"). But it will run your whole script as root. If you just want a specific command to be run as root , just prefix your command with sudo as so:

    sudo "enter_your_command_to_be_run_as_root_here"