linuxsshjenkinsremote-accesssudo

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


Using 'Execute shell script on remote host using ssh' option and need sudo rights on remote server to change permissions and remove protected files. How to run session with this rights?

Getting message

sudo: sorry, you must have a tty to run sudo

when trying to run sudo command.


Solution

  • 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.