zoukankan      html  css  js  c++  java
  • expect --批量传递公钥

    #!/binbash
    ! rpm -qa |grep expect &> /dev/null && yum -y install expect   #判断是否已下载expect 若没有则下载该服务
    if [ ! -e /root/.ssh/id_rsa.pub ];then                 #判断公钥是否已存在 没有则生成 /usr/bin/expect <<EOF set timeout 10 spawn ssh-keygen expect "id_rsa" send " " expect "passphrase" send " " expect "agian" send " " expect eof EOF fi while read file;do                     #遍历文件(ip 密码) ip=`echo "$file" |awk '{print $1}'`      #截取出ip passwd=`echo "$file" | awk '{print $2}'`   #截取出密码 /usr/bin/expect <<EOF set timeout 5 spawn ssh-copy-id -i $ip expect { "yes" { send "yes "; exp_continue } "$ip" { send "$passwd " } } expect eof EOF done < /root/host_name                   #保存ip 密码的文件路径 可自定义

    cat /root/host_name

    192.168.198.150    xxxxxxx
    192.168.198.151    xxxxxxx
    192.168.198.152    xxxxxxx
    192.168.198.153    xxxxxxx
    ......
  • 相关阅读:
    1212321
    123123
    好好干活
    VXLAN学习之路-结合VRF在Linux中实践VXLAN网络
    123456
    期望
    123456
    123456
    Jenkins管理员密码忘记修改操作
    Jenkins 安装与部署详细教程
  • 原文地址:https://www.cnblogs.com/Xinenhui/p/13916228.html
Copyright © 2011-2022 走看看