0

I understand all the security risks using ssh in this way, but what I need at the moment is a few line (bash) shell script capable to log-in to the target server and just do a foo command and get back to the source host, something like:

while true
do
   ssh target foo   # Here I get the prompt for a password which
                    # I would like to give non-interactively
   sleep 1
done

I do not want to use the ssh key based authentication because what I truly need is to simulate once a second (or so) the interactive log-in process (but not-interactively!).

ztank1013
  • 6,939
  • 2
  • 22
  • 20

3 Answers3

2

You'll need to script it with expect in something like, say, perl.

Edit: You could also try scripting expect directly in bash.

Community
  • 1
  • 1
e.dan
  • 7,275
  • 1
  • 26
  • 29
0

You have to edit the SSH server to allow login based only on a key and not from a password.

Try to see if this can help you.

Of course if you can't edit the server configuration, you need to check other solutions

Andrea Carron
  • 1,001
  • 13
  • 22
0

sshpass is designed to provide a password to ssh programatically, instead of interactively. So you can replace ssh target foo by e.g. sshpass -f passwordfile ssh target foo.

Andrew Schulman
  • 3,395
  • 1
  • 21
  • 23