1

I am trying to execute a script which is present in another unix machine from my unix box using below command:

HOST=myhostname
USER=myuser

ssh -o StrictHostKeyChecking=no -l $USER $HOST "/tmp/myscript.sh"

But the command prompts me to enter the password, but I don't want the command to prompt for password, instead of that I want to pass the password as parameter for my command. But I am not able to find an option to pass the password as parameter to SSH command.

Please help me on how to send password as part of command, instead of the command to prompt it. I am using BASH shell script.

Chaitanya
  • 15,403
  • 35
  • 96
  • 137

1 Answers1

0

Use EXPECT

Save this as mylogin.exp (or some other name you like), and change the names and password:

#!/usr/bin/expect -f
spawn ssh myname@some_server.com
expect {
   password:   {send "mypassword\n"}
}
interact

Then just run the command:

./mylogin.exp

That will just get you logged in. If you want to run a command instead, you can just put that at the end of the ssh command.

Jack
  • 5,801
  • 1
  • 15
  • 20