I execute the following command:

ssh -l admin hostname command

Each time I execute it, I am asked to enter a password. How can I automatically provide it with a password since I am going to put this in a bash script?

link|improve this question

The standard method to accomplish something like this is to use [key-based authentication][serverfault.com/search?q=ssh+key+authentication]. Follow the link to see lots of SF questions on the topic. – Zoredache Oct 3 '10 at 7:27
feedback

2 Answers

up vote 4 down vote accepted

No problem. Make keys without a password: http://linuxproblem.org/art_9.html

link|improve this answer
feedback

If ssh server not support publickey, use expect script

#!/usr/bin/expect -f
set ipaddr [lrange $argv 0 0]
spawn ssh admin@$ipaddr
expect "Password:"
sleep 1
send "PASSWORD\r"
interact

And run

./script hostname
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.