Skip to content

Run a Rundeck Command as a Different User

September 6th, 2018 - SoftwareTutorial(1 min)

TL;DR: Add the rundeck user to the sudoers and then use sudo

Installing rundeck on Ubuntu usually results in creating a rundeck user. We had a bunch of issues creating a rundeck job because we needed to execute a command as a specific user (only that user had access to some resources). Unfortunately, rundeck is not as versatile as Jenkins (plugins and such) – or I couldn’t find anything relevant at the time.

Initially, I’ve tried adding the rundeck user to the same group as the other user, but only with limited success. So, in order to make things clear, I’ve decided to add the rundeck user to the list of users capable of executing the sudo command:

# As root:
usermod -aG sudo rundeck

You can go a step further and make the sudo -u myuser run a command without password.

Then, I could run a command as the other user:

export https_proxy=http://proxy.server:8010 && \
  cd /home/myuser/dev && \
  sudo mvn clean && \
  whoami && \
  sudo -u myuser mvn deploy

Here, whoami would give me rundeck and the last command would execute nicely as the desired user.

HTH,

Share on
Reddit
Linked in
Whatsapp

A little experiment: