zoukankan      html  css  js  c++  java
  • shell脚本批量推送公钥

    目的:新建管理机,为了实现批量管理主机,设置密匙登陆

    原理:.通过密钥登陆,可以不用密码

    操作过程:

    1.生成密匙

    ssh-keygen

    2.查看密匙

    ls   ~/.ssh/

    有私匙id_rsa公匙id_rsa.pub

    3.单个发送公匙

    ssh-copy-id   -i ~/.ssh/id_rsa.pub   用户名@用户ip地址

    例:ssh-copy-id   -i ~/.ssh/id_rsa.pub   root@192.168.1.100

    4.批量推送公匙

    先安装expect:yum  -y install expect

    [root@localhost wang]# vim sshCopyId.sh
    #!/bin/bash
    for i in 192.168.100.{172..176} #定义i变量,逐个查看
    do
    password="jianchi"
    /usr/bin/expect -c "
    spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$i
    expect {
    "*(yes/no)" { send "yes ";exp_continue }
    "*password" { send "$password "; exp_continue }
    }
    expect eof"
    done

  • 相关阅读:
    nodejs
    socket.io
    how to develop mobile web
    nodejs
    GitHub
    angularJS vs backbone
    AngularJS
    oracle 数据库中数据导出到excel
    cocos2d-x中的二段构造模式
    HDOJ 4975 A simple Gaussian elimination problem.
  • 原文地址:https://www.cnblogs.com/szy2018/p/10476280.html
Copyright © 2011-2022 走看看