zoukankan      html  css  js  c++  java
  • linux 配置ssh免密码登录脚本

    首先安装expect

    yum install expect
    yum install expect-devel
    yum install tcl

    ssh-keygen -t rsa -P '' -f /home/dp/.ssh/id_rsa

    cat /home/dp/.ssh/id_rsa.pub >/home/dp/.ssh/authorized_keys

    #上面是自动生成公钥和私钥。不需要三次回车

    chmod 600 /home/dp/.ssh/id_rsa
    chmod 644 /home/dp/.ssh/authorized_keys

    cat /home/dp/ip.txt|while read line   //里面有账号与密码

    do

    ip=`echo $line|awk '{print $1}'` #把赋给ip
    echo $ip
    pw=`echo $line|awk '{print $2}'` #把密码赋给变量pw
    echo $pw
    command1="ssh-copy-id -i /home/dp/.ssh/authorized_keys dp@$ip:/home/dp/"  #这里使用-i指定文件,和使用的绝对路径,就是怕其他错误的麻烦。这个命令复制公钥比使用scp简单。

    expect -c "

    spawn $command1;

    expect {

    "password:" {send"$pw "; exp_continue}

    "connecting(yes/no)?" {send "yes "; exp_continue}

    }

    "
    done

    ssh -t -p 22 dp@$ip 'sed -i"s/^#RSAAuthentication yes/RSAAuthentication yes/g"/etc/ssh/sshd_config'

    ssh -t -p 22 dp@$ip 'sed -i"s/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g"/etc/ssh/sshd_config'

    ssh -t -p 22 dp@$ip 'sed -i"s/^#PermitRootLogin yes/PermitRootLogin yes/g"/etc/ssh/sshd_config

    chmod 644 /home/dp/.ssh/authorized_keys

    '

  • 相关阅读:
    国内外DNS服务器地址列表
    MySQL语法大全_自己整理的学习笔记(摘抄)
    http代理和sock5代理有什么区别
    sql anywhere 网络连接
    ASCII码表_全_完整版
    libevent 编写问答服务器
    简单实现h264转ts
    libevent1.4 阅读记录三
    libevent1.4 阅读记录二
    nginx 学习
  • 原文地址:https://www.cnblogs.com/sunt9/p/6690422.html
Copyright © 2011-2022 走看看