ssh 개인 키 대량 배치

1255 단어
#!/bin/bash  
# auto copy publick key to ssh server,but you must create the rsa public key first!   
# include a  expect expect script 
# see the log file  /tmp/test.log 
# see the failure log file /tmp/down.log
#    ssh  ,    "westos"
#  expect 
if
  rpm -q expect
  then
   echo "good" >/dev/null
else
   echo "you must install the expect package"
fi
    
cat > /tmp/auto.tcl << end
#!/usr/bin/expect -f 
set timeout 5 
#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 "westos\r" 
expect end
end

#!/bin/bash
chmod 755 /tmp/auto.tcl
rm -f /root/.ssh/known_hosts
for i in {46,56,66}
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

좋은 웹페이지 즐겨찾기