0

I am using script to loggin my VM2 from VM1 (Password of the VM2: fifa):

for i in {a..z}{a..z}{a..z}{a..z} 

do

# $i as a password

ssh root@ipaddress 

read i

echo $i

done

bit it doesn't work. It always ask me to enter the password. How can I make it to enter password automatically?

Kusalananda
  • 333,661
Invoker
  • 1,393
  • 1
  • 16
  • 21

1 Answers1

0

It's asking you to enter "the password" because of the read i statement, which is clobbering your for loop variable. I believe the ssh client tries to read from the tty; I'm not aware of a direct way to pass a password to ssh. Alternatives include sshpass and expect. See SSH login with clear text password as a parameter? and https://stackoverflow.com/questions/233217/pass-password-to-su-sudo-ssh and https://stackoverflow.com/questions/12118308/command-line-to-execute-ssh-with-password-authentication

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255