zoukankan      html  css  js  c++  java
  • 免密脚本带端口

    1.主要脚本

    vi mianmi.sh

    #!/bin/bash
    #------------------------------------------#
    # FileName: 自动批量免密登陆
    #maker=zsl
    echo "" >/root/b.txt
    rpm -q expect &>/dev/null
    if [ $? -ne 0 ];then
    yum -y install expect
    fi
    if [ ! -f /root/.ssh/id_rsa.pub ];then
    ssh-keygen -P "" -f /root/.ssh/id_rsa &>/dev/null # 密钥对不存在则创建密钥
    fi
    while read line;do
    ip=`echo $line | cut -d " " -f1` # 提取文件中的ip
    user_name=`echo $line | cut -d " " -f2` # 提取文件中的用户名
    pass_word=`echo $line | cut -d " " -f3` # 提取文件中的密码
    port=`echo $line | cut -d " " -f4` #提取端口
    ping -c1 -Wl $ip &>/dev/null
    if [ $? -eq 0 ];then
    { echo "ssh -p $port $user_name@$ip">>/root/b.txt
    expect <<EOF
    set timeout 4
    spawn ssh-copy-id -i /root/.ssh/id_rsa.pub -p $port $user_name@$ip
    expect {
    "yes/no" { send "yes ";exp_continue}
    "password" { send "$pass_word "}
    }
    expect eof
    EOF
    }
    fi
    continue
    done < /opt/ip.txt

    vi /opt/ip.txt

    192.168.1.62 root 123456 22
    192.168.1.64 root 123456 23

     如果卡住 ctrl +c 取消多推几次

  • 相关阅读:
    MySQL:逻辑库与表管理
    MySQL:初识数据库
    MySQL:安装与配置
    C语言之指针
    C语言之二维数组
    C语言之冒泡排序
    C语言之数组
    C语言之函数的声明
    C语言之带有返回值的函数
    C语言之全局变量和局部变量
  • 原文地址:https://www.cnblogs.com/zsl-find/p/10211451.html
Copyright © 2011-2022 走看看