公開鍵のスクリプトを大量に追加すると、大量の管理サーバに有利ですよ。



もしあなたのサーバーのipに一定の範囲があるならば、例えば192.168.0.1-1292.168.0.100間で、その上彼らのrootユーザーのパスワードは同じで、すべてredhatです。次のシナリオで迅速な配置信頼関係ができます。
 
これらのスクリプトはrhel 5システムでテストしてもokです。
 

  
  
  
  
  1. #!/bin/bash 
  2.  
  3. # auto copy publick key to ssh server,but you must create the rsa public key first
  4.  
  5. # auth: [email protected] 
  6.  
  7. date: 20100408 
  8.  
  9. # include a  expect expect script 
  10.  
  11. # see the log file  /tmp/test.log 
  12.  
  13.   
  14. if
  15. rpm -q expect
  16. then
  17. echo "Good" >/dev/null
  18. else
  19. ehco "you must install the expect package";exit 0
  20. fi
  21.  
  22. cat>/tmp/auto.tcl<<eof 
  23.  
  24. #!/usr/bin/expect -f 
  25.  
  26. set timeout -1 
  27.  
  28. #set user [lrange $argv 1 1] 
  29.  
  30. #set password [lrange $argv 2 2] 
  31.  
  32. set ipaddr [lrange \$argv 0 0] 
  33.  
  34. spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@\$ipaddr 
  35.  
  36. expect  "Are you sure you want to continue connecting (yes/no)?" 
  37.  
  38. send "yes\r" 
  39.  
  40. expect "*?assword:" 
  41.  
  42. send "redhat\r" 
  43.  
  44. expect eof 
  45.  
  46. eof 
  47.  
  48. chmod 755 /tmp/auto.tcl 
  49.  
  50.   
  51.  
  52. rm -f /root/.ssh/known_hosts 
  53.  
  54. for i in {1..100} 
  55.  
  56. do 
  57.  
  58. if 
  59.  
  60. ping -c2 192.168.0.$i &>/dev/null 
  61.  
  62. then 
  63.  
  64. /tmp/auto.tcl 192.168.0.$i &>/dev/null 
  65.  
  66. echo "********192.168.0.$i**************">>/tmp/test.log 
  67.  
  68. ssh 192.168.0.$i ifconfig eth0|grep 'inet addr:'|cut -f2 -d:|cut -f1 -d' ' >>/tmp/test.log 
  69.  
  70. else 
  71.  
  72. echo "the server 192.168.0.$i is't exsit">>/tmp/down.log 
  73.  
  74. fi 
  75.  
  76.  
  77. done 

 

 

ip,root ? , server.txt

ip :root

 

202.19.1.3:qwz234

201.19.1.2: de123s

...

 

 


   
   
   
   
  1. #!/bin/bash 
  2.  
  3. # auto copy publick key to ssh server,but you must create the rsa public key first
  4.  
  5. # auth: [email protected] 
  6.  
  7. date: 20100408 
  8.  
  9. # include a  expect expect script 
  10.  
  11. # see the log file  /tmp/test.log 
  12.  
  13.  if
  14. rpm -q expect
  15. then
  16. echo "good" >/dev/null
  17. else
  18. echo "you must install the expect package"
  19. fi 
  20.  
  21. cat>/tmp/auto.tcl<<eof 
  22.  
  23. #!/usr/bin/expect -f 
  24.  
  25. set timeout -1 
  26.  
  27. #set user [lrange $argv 2 2] 
  28.  
  29. set password [lrange \$argv 1 1] 
  30.  
  31. set ipaddr [lrange \$argv 0 0] 
  32.  
  33. spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@\$ipaddr 
  34.  
  35. expect  "Are you sure you want to continue connecting (yes/no)?" 
  36.  
  37. send "yes\r" 
  38.  
  39. expect "*?assword:" 
  40.  
  41. send "$password\r" 
  42.  
  43. expect eof 
  44.  
  45. eof 
  46.  
  47. chmod 755 /tmp/auto.tcl 
  48.  
  49.   
  50.  
  51. rm -f /root/.ssh/known_hosts 
  52.  
  53. for i in `cat /server.txt` 
  54.  
  55. do 
  56.  
  57. IP=`echo $i|cut -f1 -d:` 
  58.  
  59. PASS=`echo $i|cut -f2 -d:` 
  60.  
  61. if 
  62.  
  63. ping -c2 $IP &>/dev/null 
  64.  
  65. then 
  66.  
  67. /tmp/auto.tcl $IP $PASS &>/dev/null 
  68.  
  69. echo "********$IP**************">>/tmp/test.log 
  70.  
  71. ssh $IP ifconfig eth0|grep 'inet addr:'|cut -f2 -d:|cut -f1 -d' ' >>/tmp/test.log 
  72.  
  73. else 
  74.  
  75. echo "the server $IP is down">>/tmp/down.log 
  76.  
  77. fi 
  78.  
  79. done 
  80.  
  81.