1.建立一个ip,端口,用户,密码列表

[root@localhost shell-key]# cat arg_list.txt
172.16.56.237 clouds root 172.16.56.215
172.16.56.53 clouds root 172.16.56.215
172.16.56.215 clouds root 172.16.56.215
[root@localhost shell-key]#

2.建立expect交互交脚本:

[root@localhost shell-key]# cat expect_run_config.exp
#!/usr/bin/expect -f
set ip [lindex $argv ]
set passwd [lindex $argv ]
set username [lindex $argv ]
set port [lindex $argv ]
set localip [lindex $argv ]
set ssh_file [lindex $argv ] set remo_ip [lindex $argv ]
set key_name [lindex $argv ]
set timeout #
#create the key in the every node
#生成公共密钥 spawn ssh $username@$ip
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$passwd\r" }
} expect "*#\n"
send "rm -fr /root/.ssh\r"
send "mkdir /root/.ssh\r"
send "chmod 700 /root/.ssh\r"
send "cd /root/.ssh\r"
send "ssh-keygen\r" expect "*_rsa):"
send "\r"
expect "*ase):"
send "\r"
expect "*again:"
send "\r" expect "#\n"
send "exit\r"
expect eof spawn ssh $username@$remo_ip expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "$passwd\r" }
} expect "*#\n"
send "scp /root/.ssh/id_rsa.pub $username@$localip:/root/shell-key/pub_key/$key_name\r"
expect "*(yes/no)?"
send "yes\r" expect "*password: \n"
send "$passwd\r" #expect "*password:\n"
#send "$passwd\r" expect "*#\n"
send "exit\r"
expect eof [root@localhost shell-key]#

3.建立一个shell循环脚本:

[root@localhost shell-key]# cat loop-out.sh
#!/bin/sh
#loop_sh.sh
echo "########******loding*******#########"
rm -fr /root/shell-key/pub_key/*
rm -fr /root/shell-key/hello.txt while read line
do
echo $line >> hello.txt
done < arg_list.txt
sleep 3 rm -fr /root/shell-key/exp_list.txt while read sl
do
echo $sl | sed "s/$/ ${RANDOM}.key/" >> exp_list.txt
done < hello.txt sleep 3 while read list
do
echo $list | awk '{print $1}'
rem_ip=$(echo $list | awk '{print $1}')
rem_keyname=$(echo $list | awk '{print $6}')
./expect_run_config.exp $list $rem_ip $rem_keyname
done < exp_list.txt cat /root/shell-key/pub_key/* > /root/.ssh/authorized_keys if [ $? -eq 0 ];then
echo "******************************************"
echo "Congratulations, you create a public key *"
echo "******************************************"
else
echo "Please check_your script $0 and expect config! "
echo "Good luck !"
fi
[root@localhost shell-key]#

4.执行脚本:

[root@localhost shell-key]# ./loop-out.sh 

遍地是高手,我是菜鸟中的菜鸟,不喜勿喷!!!

ssh互信自动化脚本(待更新)的更多相关文章

  1. 纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例

    查看完整文章点击原文链接:纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例 你是否还在用postman\jmeter做接口自动化吗?用python的开源框架[unit ...

  2. 20181225-Linux Shell Bash环境下自动化创建ssh互信脚本

    20181225-Linux Shell Bash环境下自动化创建ssh互信脚本 1. 我的Blog 博客园 https://www.cnblogs.com/piggybaba/ 个人网站 http: ...

  3. 批量配置SSH互信脚本

    在大规模自动化部署时我们常常需要配置好服务器的SSH互信,以便自动化脚本可以免密登录远程服务器,常规的手动配置SSH互信步骤如下: 使用ssh-keygen生成本地ssh key(mha01),生成的 ...

  4. Ansible批量更新远程主机用户密码 (包括Ansible批量做ssh互信)

    按照集团运维信息安全制度, 需要每个一段时间对线上服务器密码进行一次变更,通过shell脚本部署比较繁琐,所以决定采用ansible脚本对远程主机root密码进行批量重置,该脚本已经在稳定运行在正式环 ...

  5. ezdpl:完全依赖脚本和ssh的自动化部署方案

    ezdpl是easy deployment的简写,使用简单的ssh和shell脚本来部署.升级.回滚和重新配置linux服务器. 重要提示:警告:这个项目还处于测试过程中,请仔细阅读说明,并且自己承担 ...

  6. Linux快速配置集群ssh互信

    之前在<记录一则Linux SSH的互信配置过程>.<Vertica 7.1安装最佳实践(RHEL6.4)>中,都分别提到了配置ssh互信的方法,本文在此基础上进一步整理配置s ...

  7. linux配置ssh互信

    公钥认证的基本思想: 对信息的加密和解密采用不同的key,这对key分别称作private key和public key,其中,public key存放在欲登录的服务器上,而private key为特 ...

  8. Salt自动化之自动更新Gitfs-爱折腾技术网

    Salt自动化之自动更新Gitfs-爱折腾技术网 pygit2

  9. 制作ssh互信的docker镜像

    Dockerfile FROM ubuntu:16.04 # package RUN apt-get update; apt-get -y install ssh COPY ssh_config /e ...

随机推荐

  1. T-SQL切割字符串方法小结 2

    有表tb, 如下: id value ----------- ----------- 1 aa,bb 2 aaa,bbb,ccc 欲按id,分拆value列, 分拆后结果如下: id value -- ...

  2. 完全步卸载oracle11g步骤

    完全 步 卸载oracle11g骤: . 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.  . 开始->程序->Oracle - OraH ...

  3. PHP 内存不足

    今天编写数据库备份类时,在运行的过程中,出现了内存不足的问题,提示:Fatal error: Allowed memory size of 25165824 bytes exhausted (trie ...

  4. CentOS 6.4 64位 安装 apache-tomcat-6.0.43

    下载 tomcat: 地址:http://mirrors.hust.edu.cn/apache/tomcat/tomcat-6/v6.0.43/bin/apache-tomcat-6.0.43.tar ...

  5. GoJS研究,简单图表制作。

    话不多说,先上图 我在这个中加入了缩略图.鼠标放大缩小等功能. <!doctype html> <html> <head> <title>Flowcha ...

  6. jQuery获取Select选择的Text和 Value

    jQuery获取Select选择的Text和Value:语法解释:1. $("#select_id").change(function(){//code...});   //为Se ...

  7. 使用PHP脚本来写Daemon程序

    什么是Daemon进程   这又是一个有趣的概念,daemon在英语中是"精灵"的意思,就像我们经常在迪斯尼动画里见到的那些,有些会飞,有些不会,经常围着动画片的主人公转来转去,啰 ...

  8. InstallShield:自己备份

    LIST listData;//声明listData listData = ListCreate(STRINGLIST);//创建一个空的实际字符串或数字列表. //参数都是在上个界面中赋值,然后在下 ...

  9. baba 运动网

    import com.sun.image.codec.jpeg.* 找不到包     在Myeclipse中编译项目时,如果提示类似 com.sun.image.codec.jpeg.* 下: imp ...

  10. 从string.size()和string.length()聊到长度的问题和一个关于数据结构定义的技巧

    最近工作中要查看一下string的长度,然后忘了是哪个函数,所以去网上搜了一搜,决定把网上学的和其他的一些有关长度的东西在这里汇总一下, 然后就有了此帖. string 是从c语言的char数组的概念 ...