0

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?

Zoredache
  • 130,897
  • 41
  • 276
  • 420
Mohammad AL-Rawabdeh
  • 1,612
  • 12
  • 33
  • 54
  • The standard method to accomplish something like this is to use [key-based authentication][http://serverfault.com/search?q=ssh+key+authentication]. Follow the link to see lots of SF questions on the topic. – Zoredache Oct 03 '10 at 07:27

2 Answers2

4

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

igelkott
  • 233
  • 3
  • 8
2

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
bindbn
  • 5,211
  • 2
  • 26
  • 24