zoukankan      html  css  js  c++  java
  • shell_跳板机推送公钥

    #!/bin/bash
    #push publickey to aap-servers
    #将局域网内可以ping通的主机ip保存到一个文件
    > ip_up.txt
    for i in {2..10}
    do
    {
    ip=10.1.1.$i
    ping -c1 $ip &>/dev/null
    [ $? -eq 0 ] && echo $ip |tee -a ip_up.txt
    }& //并行放到后台运行
    done
    wait //等待进程结束
    #将yunwei用户目录下的公钥推送到可以ping的服务器上
    #1. 判断yunwei用户下有没有公钥
    [ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -P "" -f ~/.ssh/id_rsa

    #2.将id_rsa.pub公钥远程推送到指定服务器
    #2.1 判断expect程序是否安装,没安装则安装它
    {
    rpm -q expect
    [ $? -ne 0 ] && sudo yum -y install expect

    for remote_ip in `cat ip_up.txt`
    do
    /usr/bin/expect <<-EOF
    spawn ssh-copy-id root@$remote_ip
    expect {
    "yes/no" { send "yes ";exp_continue }
    "password:" { send "123 " }
    }
    expect eof
    EOF
    done
    } &>/dev/null
    #测试验证
    test_ip=`tail -1 ip_up.txt`
    ssh root@$test_ip hostname
    test $? -eq 0 && echo "公钥推送成功。"

    坚持这种真诚,那么总归能遇到良人。
  • 相关阅读:
    jq---方法总结
    Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness
    Coin
    joisino's travel
    日天的终生大事(dp)
    Codefroces 852 G. Bathroom terminal
    Codefroces432 div2 A,B,C
    Atcoder ABC 069 C
    Codefroces 849 A,B
    HDU 6186 CS Course
  • 原文地址:https://www.cnblogs.com/jiaxiaozia/p/12161573.html
Copyright © 2011-2022 走看看