3

I need to execute a bash script as sudo on a remote linux machine from TeamCity running on a windows box. I can execute the script fine from the cmd line using plink, but I am prompted for a password. I need to be able to do this without being prompted for password in order to execute from teamcity.

What are my options?

3 Answers 3

2

You need to edit the sudo configuration on the host you want to run the script. Run visudo as root and add a line like this:

USERNAME ALL=(ALL) NOPASSWD: ALL

Replace USERNAME with the user you want to run the script with. This should enable the user to use sudo without entering the password. You might want to limit the use of sudo to the commands you actually need. Look in the sudoers by using visudo for examples how to achieve that.

2
  • This prevents being prompted for a password when I have an SSH session but not when I use plink from windows : plink -ssh -pw {pwd} -t user@{ipaddr} /{dir}/{script} Nov 3, 2015 at 15:56
  • ok, sorry. I guess I got your question wrong. So your problem is about providing the login password with plink? Have you tried providing the password with -pw password parameter? linux.die.net/man/1/plink Nov 3, 2015 at 16:06
0

If both systems are secured you can use something like this:

echo 'sudo_password' | sudo -S command

This option has to be used with care since it uses the password in clear and other users logged in into that machine might see it.

0

One option is to just allow ssh access directly to the root account of the machine. You should lock this with a private key, and probably password protect that key. Add something like the following to your sshd_config:

PermitRootLogin yes
Match User root
  PasswordAuthentication no

If you go this route, you can make this key run the specific command script regardless of what has been specicfied by adding command="" in the ~root/authorized_hosts file, e.g.

command="/root/myscript" ssh-rsa AAAB3NzaC1yc2EAAAABIwAAADV4//KSz...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .