How to run remote ssh session from Jenkins with sudo rights? How to run remote ssh session from Jenkins with sudo rights? jenkins jenkins

How to run remote ssh session from Jenkins with sudo rights?


To run sudo remotely you have 2 options

  1. Allow the user to run sudo commands without a password.

Append username ALL=(ALL) NOPASSWD: ALL the /etc/sudoers file with sudo visudo. Alternatively you can modify this line to only allow certain sudo commands to be run without a password

  1. Use the pseudo-tty to emulate tty remotely and enter your sudo password when requsted.

To do this run ssh -t username@host command_to_execute


If the remote server accepts the direct login of the root user you can simply do:

ssh -l root yourserver command_to_execute

Similar syntax is:

ssh root@yourserver command_to_execute

Mind that allowing the login of the root user via ssh to a remote server isn't always a good solution.A better solution would be change the owner / permissions to allow a non-root user to modify the protected files.