zoukankan      html  css  js  c++  java
  • shell实现免密

    #!/bin/bash
    
    createLocalKey () {
        rm -rf ~/.ssh/id_rsa
        rm -rf ~/.ssh/id_rsa.pub
        /usr/bin/expect <<_oo_
    
            spawn ssh-keygen -t rsa
            expect {
                "*.ssh/id_rsa*" { send "\r";exp_continue }
                "*no passphrase*" { send "\r";exp_continue }
                "*passphrase again*" { send "\r";exp_continue }
                "Overwrite*" { send "y\r";exp_continue }
            }
            expect eof
    
    _oo_
    
    }
    
    
    copyToRemote () {
        hosts=(master slave1 slave2)
        password="root"
        for host in ${hosts[@]};
        do
          /usr/bin/expect <<_oo_
    
            spawn ssh-copy-id $host
            expect {
                "*connecting (yes/no)*" { send "yes\r";exp_continue }
                "*password*" { send "$password\r";exp_continue }
            }
    
            expect eof
    
    _oo_
        done
    }
    
    
    createLocalKey
    copyToRemote
    

      

  • 相关阅读:
    flex 自定义事件
    ssis 不停执行的方法
    动态修改大小的Panel用户控件
    ssis 写文件到数据库
    sqlserver CheckSum
    poj1423
    poj1860
    poj1862
    poj1426
    poj1234
  • 原文地址:https://www.cnblogs.com/navysummer/p/15779737.html
Copyright © 2011-2022 走看看