Providing password using a variable to become a sudo user in Jenkins Providing password using a variable to become a sudo user in Jenkins unix unix

Providing password using a variable to become a sudo user in Jenkins


Even if you get it working, having passwords in scripts or on the command line probably is not ideal from a security standpoint. Two things I would suggest :

1) Use a public SSH key owned by the user on your initiating system as an authorized key on the remote system to allow logging as the intended user on the remote system without a password. You should have all you need to do that (no root access required, only to the users you already use on each system).

2) Set-up the "sudoers" file on the remote system so that the user you log in as is allowed to perform the commands you need as the required user. You would need the system administrator help for that.


Like so:

SUDO_PASSWORD=TheSudoPassword...ssh kilroy@somehost "echo $SUDO_PASSWORD | sudo -S some_root_command"

Later

How can i use this in the 1st snippet?

Write a file:

deploy.sh

#!/bin/shcd /DIR1/DIR2cp ~/MY_APP.war .mkdir DIR 3tar -xzvf MY_APP.war

Then:

chmod +x deploy.shscp deploy.sh kilroy@somehost:~ssh kilroy@somehost "echo $SUDO_PASSWORD | sudo -S ./deploy.sh"