zoukankan      html  css  js  c++  java
  • 实现批量key验证

    基于sshpass

    在hosts.list 文件中提前写好需要key验证的机器IP

    [root@centos8 ~]# cat hosts.list
    10.0.0.1
    10.0.0.2
    10.0.0.3
    
    #!/bin/bash
    exec 1> /dev/null
    rpm -q sshpass || yum -y install sshpass
    [ -f /root/.ssh/id_rsa ] || ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa &> /dev/null
    while read IP
    do
        sshpass -p 123456 ssh-copy-id -o StrictHostKeyChecking=no $IP
    done < hosts.list
    

    也可以将需要key验证机器的IP存入变量中

    #!/bin/bash
    exec 1> /dev/null
     
    IPLIST="
    10.0.0.1
    10.0.0.2
    10.0.0.3
    "
    rpm -q sshpass || yum -y install sshpass
    [ -f /root/.ssh/id_rsa ] || ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa &> /dev/null
    for IP in $IPLIST
    do
        sshpass -p 123456 ssh-copy-id -o StrictHostKeyChecking=no $IP
    done
    

    基于expect

    #!/bin/bash
    
    rpm -q expect &> /dev/null || yum -y install expect &> /dev/null
    
    [ -f /root/.ssh/id_rsa ] || ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa &> /dev/null
    
    PASS=123456
    
    while read IP
    do
        expect &> /dev/null <<EOF  # 或者expect << EOF &> /dev/null
        set timeout 20
        spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$IP
        expect {
            "yes/no" { send "yes
    ";exp_continue }
            "password" { send "$PASS" }
        }
        expect eof
    EOF
        echo "$IP is ready"
    done < hosts.list
    
  • 相关阅读:
    spoj 104 Highways (最小生成树计数)
    bzoj 1912 巡逻(树直径)
    BZOJ 3534 重建
    BZOJ 3143 游走(高斯消元)
    在Windows下编译PyCaffe
    caffe的Matlab接口的使用方法
    NewRelic性能监控之APM
    MariaDB-10.x二进制包安装
    mongoDB-3.x Balancer Management
    mongoDB-3.x集群管理
  • 原文地址:https://www.cnblogs.com/wuvikr/p/13630802.html
Copyright © 2011-2022 走看看