Rundeck: Run job as another user

by default rundeck runs as the rundeck user. For some tasks you will need to execute the script as another user. Here is a quick rundown on how to do it.

Configuration Steps

  • Login via ssh to the server.
  • Edit /etc/sudoers and add the following lines. This will allow the rundeck user to execute sudo with no password.
vi /etc/sudoers
  • Save the file now login to the rundeck dashboard
  • Create a new job and select execute local command. we will set the command to an sudo with the following parameters. This will write a temp file and you can check to ensure everything is working.
sudo -i -u <USERNAME> /bin/bash -c 'echo "hello" > /tmp/test'Code language: JavaScript (javascript)

This executes sudo -i runs in the users environment -u specifies a user and we are running the bash command with -c to execute the echo command. This will create a test file do an ls -la to check the permissions. If all is good you can now use the above command to run scripts. Below are a few examples.

#Running a python script as user www-data
sudo -i -u www-data python3 /www/

#This runs a bash backup script located in the users home/bin directory
sudo -i -u USER /bin/bash -c  /home/USER/bin/WebBackup.shCode language: PHP (php)
Read full article here

Related posts

Leave A Comment