How to automate password entry?

I want to install the software library (SWIG) in the list of computers (Jenkins nodes). I use 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 

Thus, it is automated, with the exception of a password request, which occurs for both scp and ssh commands.

Is there a way to programmatically enter passwords?

Security is not a problem. I am looking for solutions that do not include SSH keys.

+4
source share
5 answers

With SSH, the correct way to do this is to use keys instead.

 # ssh-keygen 

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

+4
source

Here is an expect example that ssh is located in the Stripes Capture Flag server and automatically enters a password.

 expect <<< 'spawn ssh level01@ctf.stri.pe ; expect "password:"; send "e9gx26YEb2\r";' 
+5
source

You can complete the task using empty , a small utility from sourceforge. This is similar to the expectation, but probably more convenient in this case. After you install it, your first scp will be executed using the following two commands:

 ./empty -f scp InstallSWIG.sh root@ $node:/root/InstallSWIG.sh echo YOUR_SECRET_PASSWORD | ./empty -s -c 

The first runs your team in the background, tricking it into thinking that it works interactively on the terminal. Another sends data from stdin. Of course, entering a password anywhere on the command line is dangerous due to saving the shell history, users can see it in ps results, etc. It is unsafe, but it would be a little better to store the password in the file and redirect the second input of the command from this file instead of using the echo and channel.

After copying to the server, you can run the script in the same way:

 ./empty -f ssh root@ $node sh InstallSWIG.sh echo YOUR_SECRET_PASSWORD | ./empty -s -c 
+2
source

You can look at the setting for this without an ssh password. Establishing a batch connection between OpenSSH and SSH2 is the starting point; you will find a lot of information on this topic on the Internet.

+1
source

Wes answer is correct, but if you are fond of something dirty and slow, you can use expect to automate this,

0
source

Source: https://habr.com/ru/post/1346237/


All Articles