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

    '

  • 相关阅读:
    [总结]链表与栈
    统计学基础知识
    图卷积神经网络(GCN)入门
    [总结]字符串
    [总结]数组
    [总结]排序算法分析与实现
    [Leetcode]307. Range Sum Query
    深度解析Droupout与Batch Normalization
    深度解析Graph Embedding
    Console命令,让js调试更简单
  • 原文地址:https://www.cnblogs.com/sunt9/p/6690422.html
Copyright © 2011-2022 走看看