ssh互信自动化脚本(待更新)
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互信自动化脚本(待更新)的更多相关文章
- 纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例
查看完整文章点击原文链接:纯python自研接口自动化脚本更新版本,让小白也能实现0到1万+的接口自动化用例 你是否还在用postman\jmeter做接口自动化吗?用python的开源框架[unit ...
- 20181225-Linux Shell Bash环境下自动化创建ssh互信脚本
20181225-Linux Shell Bash环境下自动化创建ssh互信脚本 1. 我的Blog 博客园 https://www.cnblogs.com/piggybaba/ 个人网站 http: ...
- 批量配置SSH互信脚本
在大规模自动化部署时我们常常需要配置好服务器的SSH互信,以便自动化脚本可以免密登录远程服务器,常规的手动配置SSH互信步骤如下: 使用ssh-keygen生成本地ssh key(mha01),生成的 ...
- Ansible批量更新远程主机用户密码 (包括Ansible批量做ssh互信)
按照集团运维信息安全制度, 需要每个一段时间对线上服务器密码进行一次变更,通过shell脚本部署比较繁琐,所以决定采用ansible脚本对远程主机root密码进行批量重置,该脚本已经在稳定运行在正式环 ...
- ezdpl:完全依赖脚本和ssh的自动化部署方案
ezdpl是easy deployment的简写,使用简单的ssh和shell脚本来部署.升级.回滚和重新配置linux服务器. 重要提示:警告:这个项目还处于测试过程中,请仔细阅读说明,并且自己承担 ...
- Linux快速配置集群ssh互信
之前在<记录一则Linux SSH的互信配置过程>.<Vertica 7.1安装最佳实践(RHEL6.4)>中,都分别提到了配置ssh互信的方法,本文在此基础上进一步整理配置s ...
- linux配置ssh互信
公钥认证的基本思想: 对信息的加密和解密采用不同的key,这对key分别称作private key和public key,其中,public key存放在欲登录的服务器上,而private key为特 ...
- Salt自动化之自动更新Gitfs-爱折腾技术网
Salt自动化之自动更新Gitfs-爱折腾技术网 pygit2
- 制作ssh互信的docker镜像
Dockerfile FROM ubuntu:16.04 # package RUN apt-get update; apt-get -y install ssh COPY ssh_config /e ...
随机推荐
- vi 替换字符串
假如说我想把该文件中所有的Web替换成SOR_SYS,那么我们可以用vi打开该文件,然后按一下: 你的命令行的最后一行会出现:,这个时候就是提醒你输入替换的命令 %s/Web/SOR_SYS/g 按一 ...
- 2.Oracle11g体系结构
2.1逻辑存储结构 2.1.1数据块(Data Blocks) 数据块是Oracle逻辑结构中最小的逻辑单位,也是执行数据库输入输出最小的存储单位.通常Oracle数据库是操作系统块的整数倍,如果操作 ...
- python中文问题汇总
1.中文路径 #-*-coding:utf-8-*- path=ur'E:\accumulate\Python\语法\08输入和输出\1.txt' #python内部使用的是unicode,不加前缀u ...
- Quartz-2D绘图之路径(Paths)详解
在上篇文章中,我们简单的理解了绘图上下文,今天我们来认识一下Quartz-2D中另一个重要的概念,路径(Paths). 一.理解路径 路径定义了一个或多个形状,或是子路径.一个子路径可由直线,曲线,或 ...
- Java OOP考试错题分析
解析: A.ArrayList 可以存储NULL值,也可以存储重复的值,对集合没有任何影响. B.一旦实例化不可改变自身大小,这是数组的特性.集合的容量是自身扩容的. C.ArrayList可以存 ...
- 安装sql server 2008,提示要删除SQL Server 2005 Express 工具 怎么解决?
x86 修改注册表:HKLM\Software\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM,把 ShellSEM重命名即可. x64 ...
- VBA开发经验总结之一:利用Range对象设计用户界面
读罢<EXCEL专业开发>,最大的震撼就是著者对VBA技术的追求以及对Excel艺术品般的设计.受到此书著者的启发,也打算把自己在日常开发中一些经验总结出来,一来作为自己的知识储备,二来也 ...
- [转] 博闻强识:了解CSS中的@ AT规则 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=4900 大家可能在CS ...
- ext 扩展控件—moneyField
/** *数字控件 *带大写提示,和千分位 **/ Ext.define(appNameSpace+'.utils.MoneyField', { extend : 'Ext.form.field.Te ...
- CodeIgniter框架介绍
入口 index.php :一些路径常量定义: => CodeIgniter.php : 1. 初始化一些 system/core内的类,例如Config, Utf8, URI 和Router等 ...