公開鍵のスクリプトを大量に追加すると、大量の管理サーバに有利ですよ。
もしあなたのサーバーのipに一定の範囲があるならば、例えば192.168.0.1-1292.168.0.100間で、その上彼らのrootユーザーのパスワードは同じで、すべてredhatです。次のシナリオで迅速な配置信頼関係ができます。
これらのスクリプトはrhel 5システムでテストしてもokです。
- #!/bin/bash
-
- # auto copy publick key to ssh server,but you must create the rsa public key first!
-
- # auth: [email protected]
-
- # date: 20100408
-
- # include a expect expect script
-
- # see the log file /tmp/test.log
-
-
- if
- rpm -q expect
- then
- echo "Good" >/dev/null
- else
- ehco "you must install the expect package";exit 0
- fi
-
- cat>/tmp/auto.tcl<<eof
-
- #!/usr/bin/expect -f
-
- set timeout -1
-
- #set user [lrange $argv 1 1]
-
- #set password [lrange $argv 2 2]
-
- set ipaddr [lrange \$argv 0 0]
-
- spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@\$ipaddr
-
- expect "Are you sure you want to continue connecting (yes/no)?"
-
- send "yes\r"
-
- expect "*?assword:"
-
- send "redhat\r"
-
- expect eof
-
- eof
-
- chmod 755 /tmp/auto.tcl
-
-
-
- rm -f /root/.ssh/known_hosts
-
- for i in {1..100}
-
- do
-
- if
-
- ping -c2 192.168.0.$i &>/dev/null
-
- then
-
- /tmp/auto.tcl 192.168.0.$i &>/dev/null
-
- echo "********192.168.0.$i**************">>/tmp/test.log
-
- ssh 192.168.0.$i ifconfig eth0|grep 'inet addr:'|cut -f2 -d:|cut -f1 -d' ' >>/tmp/test.log
-
- else
-
- echo "the server 192.168.0.$i is't exsit">>/tmp/down.log
-
- fi
-
-
- done
,
ip,root ? , server.txt
ip :root
202.19.1.3:qwz234
201.19.1.2: de123s
...
- #!/bin/bash
-
- # auto copy publick key to ssh server,but you must create the rsa public key first!
-
- # auth: [email protected]
-
- # date: 20100408
-
- # include a expect expect script
-
- # see the log file /tmp/test.log
-
- if
- rpm -q expect
- then
- echo "good" >/dev/null
- else
- echo "you must install the expect package"
- fi
-
- cat>/tmp/auto.tcl<<eof
-
- #!/usr/bin/expect -f
-
- set timeout -1
-
- #set user [lrange $argv 2 2]
-
- set password [lrange \$argv 1 1]
-
- set ipaddr [lrange \$argv 0 0]
-
- spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@\$ipaddr
-
- expect "Are you sure you want to continue connecting (yes/no)?"
-
- send "yes\r"
-
- expect "*?assword:"
-
- send "$password\r"
-
- expect eof
-
- eof
-
- chmod 755 /tmp/auto.tcl
-
-
-
- rm -f /root/.ssh/known_hosts
-
- for i in `cat /server.txt`
-
- do
-
- IP=`echo $i|cut -f1 -d:`
-
- PASS=`echo $i|cut -f2 -d:`
-
- if
-
- ping -c2 $IP &>/dev/null
-
- then
-
- /tmp/auto.tcl $IP $PASS &>/dev/null
-
- echo "********$IP**************">>/tmp/test.log
-
- ssh $IP ifconfig eth0|grep 'inet addr:'|cut -f2 -d:|cut -f1 -d' ' >>/tmp/test.log
-
- else
-
- echo "the server $IP is down">>/tmp/down.log
-
- fi
-
- done
-
-