• 批量分发密钥脚本


    批量分发秘钥

    改良版1.1

    #!/bin/bash
    #前提请把公钥默认创建完成
    #例 ssh-keygen  --- 一路回车
    # yum install sshpass -y 先执行
    cat<<eof
    ********************************************
    注:yum install sshpass -y 先执行
    请输入你的网段,查看可用IP地址.  
    例:10.0.0.
    请耐心等待!
    *******************************************
    eof
    read -p "Please enter the network segment where you want to distribute the secret keys : " ip
    read -s -p "Please enter your local password :" pass
    
    echo $ip | grep -Ex '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]).((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]).){2}'  &> /dev/null
    check=$?
    sleep 3
    if [ $check -eq 0 ];
    then
    for i in ${ip}{1..255}
    
     do
    {
                    ping -c 1  $i &> /dev/null
                    if [ $? -ne 0 ];
                    then
                            echo $i &> /dev/null
                    else
                           . /etc/init.d/functions
    timeout 5 sshpass -p$pass ssh-copy-id -f -i  ~/.ssh/id_rsa.pub root@$i -o StrictHostKeyChecking=no  &> /dev/null
                            if [ $? -eq 0 ]
                            then
                            action   "主机 $i"     /bin/true
                            echo   ""
                            else
                            action   "主机 $i"     /bin/false
                            echo   ""
                            fi
                    fi
    }&
            done
    else
       echo  "当前仅支持ipv4格式且是十进制,请重新输入"
    fi
    wait
    echo "结束"

    改良版1.0

    #!/bin/bash
    for i in `cat /etc/ansible/ip.txt`
            do
    {
                    ping -c 1  $i &>/dev/null
                    if [ $? -ne 0 ];
                    then
                            echo $i &> /dev/null
                    else
                            echo $i > /dev/null
                            # yum install sshpass -y 
                            #创建秘钥
                            # ssh-keygen
                            service network start *> /dev/null
                            . /etc/init.d/functions
                   yum install sshpass -y &> /dev/null
    
                            for ipadd in $i
                            do
                            sshpass -pnihao123! ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i -o StrictHostKeyChecking=no &>/dev/null
                            if [ $? -eq 0 ]
                            then
                            action   "主机 $i"     /bin/true
                            echo   ""
                            else
                            action   "主机 $i"     /bin/false
                            echo   ""
                            fi
                            done
                    fi
    }&
            done
    exit 0

    原版

    #!/bin/bash
    #前提请把公钥默认创建完成
    #例 ssh-keygen  --- 一路回车
    cat<<eof
    ********************************************
    请输入你的网段,查看可用IP地址.  
    例:10.0.0
    请耐心等待!
    *******************************************
    eof
    read -p "Please enter the network segment where you want to distribute the secret keys : " ip
    read -s -p "Please enter your local password :" pass
    for i in $ip.{1..253}
            do
    {
                    ping -c 1  $i &>/dev/null
                    if [ $? -ne 0 ];
                    then
                            echo $i &> /dev/null
                    else
                            echo $i > /tmp/ip.txt
                            #先下载 yum install sshpass 
                            #创建秘钥
                            # ssh-keygen 
                            . /etc/init.d/functions
                   yum install sshpass -y *> /dev/null 
                        
                            for ipadd in `cat /tmp/ip.txt`
                            do
                            sshpass -p$pass ssh-copy-id -i ~/.ssh/id_rsa.pub root@$ipadd -o StrictHostKeyChecking=no &>/dev/null
                            if [ $? -eq 0 ]
                            then
                            action   "主机 $ipadd"     /bin/true
                            echo   ""
                            else
                            action   "主机 $ipadd"     /bin/false
                            echo   ""
                            fi
                            done
                    fi
    }&
            done
  • 相关阅读:
    c#自动更新+安装程序的制作
    VS2013项目受源代码管理向源代码管理注册此项目时出错
    WinDbg配置和使用基础
    InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
    PowerDesigner 如何生成数据库更新脚本
    用户故事(User Story)
    Troubleshooting Record and Playback issues in Coded UI Test
    Coded UI
    compare two oracle database schemas
    How to: Use Schema Compare to Compare Different Database Definitions
  • 原文地址:https://www.cnblogs.com/Mercury-linux/p/11784277.html
Copyright © 2020-2023  润新知