Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate password entry?

I want to install a software library (SWIG) on a list of computers (Jenkins nodes). I'm using the following script to automate this somewhat:

NODES="10.8.255.70 10.8.255.85 10.8.255.88 10.8.255.86 10.8.255.65 10.8.255.64 10.8.255.97 10.8.255.69"
for node in $NODES; do 
  scp InstallSWIG.sh root@$node:/root/InstallSWIG.sh
  ssh root@$node sh InstallSWIG.sh
done

This way it's automated, except for the password request that occur for both the scp and ssh commands.

Is there a way to enter the passwords programmatically?

Security is not an issue. I’m looking for solutions that don’t involve SSH keys.

like image 621
StackedCrooked Avatar asked Dec 10 '22 09:12

StackedCrooked


2 Answers

Here’s an expect example that sshs in to Stripe’s Capture The Flag server and enters the password automatically.

expect <<< 'spawn ssh [email protected]; expect "password:"; send "e9gx26YEb2\r";'
like image 157
Mathias Bynens Avatar answered Dec 26 '22 06:12

Mathias Bynens


With SSH the right way to do it is to use keys instead.

# ssh-keygen

and then copy the *~/.ssh/id_rsa.pub* file to the remote machine (root@$node) into the remote user's .ssh/authorized_keys file.

like image 44
Wes Hardaker Avatar answered Dec 26 '22 06:12

Wes Hardaker