shell- ssh免密登录脚本

#!/bin/sh
. /etc/init.d/functions
#1.product key pair
/usr/bin/rm -f .ssh/* 2&>/dev/null
[ -f id_rsa.pub = 0 ] >/dev/null 2>&1
     ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa >/dev/null 2>&1
if [ $? -eq 0 ];then
   action "create dsa $ip" /bin/true
  else
   action "create dsa $ip" /bin/false 
    exit 1
fi
#2.dis pub key
for ip in 161 162
do
  #expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub 10.0.0.$ip >/dev/null  2>&1
  sshpass -p123456 ssh-copy-id -o StrictHostKeyChecking=no 10.0.0.$ip >/dev/null 2>&1
  if [ $? -eq 0 ];then
     action "$ip" /bin/true
  else
     action "$ip" /bin/false
  fi
done
原文地址:https://www.cnblogs.com/fengyuanfei/p/13784079.html