Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
The standard method to accomplish something like this is to use [key-based authentication][]. Follow the link to see lots of SF questions on the topic. – Zoredache Oct 3 '10 at 7:27
up vote 4 down vote accepted

No problem. Make keys without a password:

share|improve this answer

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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