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?


2 Answers 2


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


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"

And run

./script hostname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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