20181225-Linux Shell Bash环境下自动化创建ssh互信脚本
20181225-Linux Shell Bash环境下自动化创建ssh互信脚本
1. 我的Blog
博客园 https://www.cnblogs.com/piggybaba/
个人网站 http://piggybaba.cn
GitHub https://github.com/AndyYHM/Writing/
2. 简介信息
摘要:Linux下,自动化创建SSH互信脚本
Author: andy_yhm@yeah.net
Date: 20181225
关键字:Shell脚本, ssh, ssh trust ,auto,SSH互信,/bin/bash
3. 脚本输出效果
单一节点上,用户python,执行脚本后,输入三台节点python用户密码,自动化创建SSH互信关系
$ sh SSH_Trust.sh
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
python@node11's password:
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
python@node12's password:
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
python@node13's password:
Transfer authorized_keys
authorized_keys 100% 1185 1.2KB/s 00:00
known_hosts 100% 537 0.5KB/s 00:00
authorized_keys 100% 1185 1.2KB/s 00:00
known_hosts 100% 537 0.5KB/s 00:00
4. 功能说明
- 默认支持3节点自动化创建SSH互信关系
- 支持多节点自动化创建SSH互信关系
5. 使用说明
- 需要提前编辑好/etc/hosts文件
- 用户名所有主机设置为一致
- 使用前编辑脚本"config to do"部分,节点hostname和用户名
- othernodes参数需以空格” “隔开;
- 执行脚本后,需逐一输入节点用户的密码
- 若主机节点数规模庞大,建议使用
expect工具,另行编辑脚本;
6. 脚本内容
#!/usr/bin/env bash
#########################################
# Author: andy_yhm@yeah.net
# Date: 20181225
# Key Word : Shell脚本, ssh, ssh trust ,auto,SSH互信,/bin/bash
#########################################
#
## Config to do
#
node1=node11
node2=node12
node3=node13
othernodes=
user=test
#
## Please Don't edit content below
#
ssh-keygen -q -P "" -f $HOME/.ssh/id_rsa > /dev/null
for node in ${node1} ${node2} ${node3} ${othernodes}
do
if [ "`hostname`" == "$node" ]; then
ssh-copy-id -o stricthostkeychecking=no $user@$node > /dev/null
else
ssh-copy-id -o stricthostkeychecking=no python@$node > /dev/null
ssh $node 'ssh-keygen -q -P "" -f $HOME/.ssh/id_rsa' > /dev/null
scp -rp $node:$HOME/.ssh/id_rsa.pub ./auth.$node > /dev/null
fi
done
cat ./auth.* >> $HOME/.ssh/authorized_keys
rm -rf ./auth.*
echo "Transfer authorized_keys"
for node in ${node1} ${node2} ${node3} ${othernodes}
do
if [ "`hostname`" != "$node" ]; then
scp -rp $HOME/.ssh/authorized_keys $node:$HOME/.ssh/authorized_keys
scp -rp $HOME/.ssh/known_hosts $node:$HOME/.ssh/known_hosts
fi
done
exit 0
20181225-Linux Shell Bash环境下自动化创建ssh互信脚本的更多相关文章
- Linux Shell基础(下)
Linux Shell基础(下) 目录 一.shell特殊符号cut命令 二.cut.sort.wc.uniq命令 三.tee.tr.split命令 四.简易审计系统 五.fork, exec, so ...
- Linux 14.04lts 环境下搭建交叉编译环境arm-linux-gcc-4.5.1
交叉编译工具链是为了编译.链接.处理和调试跨平台体系结构的程序代码,在该环境下编译出嵌入式Linux系统所需要的操作系统.应用程序等,然后再上传到目标板上. 首 先要明确gcc 和arm-linux- ...
- linux系统Centos环境下搭建SVN服务器及权限配置
linux系统Centos环境下如何搭建SVN服务器以及svnserve.conf.authz.passwd配置文件详细介绍 至于svn的概念,这里就不做详细阐述了,可以自行百度.简单来讲就是一个 ...
- source 命令的用法,是在当前bash环境下执行脚本文件
原文: http://www.cnblogs.com/softwaretesting/archive/2012/02/13/2349550.html source命令用法: source FileNa ...
- JAVA中调用LevelDB用于Linux和Window环境下快速存储KV结构
一.简介 JAVA中调用LevelDB用于Linux和Window环境下快速存储KV结构 二.依赖 <!-- https://mvnrepository.com/artifact/org.fus ...
- 一步步教你搭建VS环境下用C#写WebDriver脚本
一步步教你搭建VS环境下用C#写WebDriver脚本http://www.automationqa.com/forum.php?mod=viewthread&tid=3529&fro ...
- Window环境下,PHP调用Python脚本
参考 php调用python脚本*** php 调用 python脚本的方法 解决办法:php提供了许多调用其他脚本或程序的方法,比如exec/system/popen/proc_open/passt ...
- Linux Bash环境下单引(')、双引号(")、反引号(`)、反斜杠(\)的小结
在bash中,$.*.?.[.].’.”.`.\.有特殊的含义.类似于编译器的预编译过程,bash在扫描命令行的过程中,会在文本层次上,优先解释所有的特殊字符,之后对转换完成的新命令行,进行内核的系统 ...
- Anaconda3+python3环境下如何创建python2环境(win+Linux下适用,同一个anaconda下py2/3共存)
本人之前已经在anaconda环境下已经安装了python3的环境,现在因为一些需求,要安装python2环境 1.打开anaconda的anaconda prompt查看当前环境: conda in ...
随机推荐
- MySql和Oracle数据库区别
Oracle与mysql区别: 1.Oracle有表空间,mysql没有表空间. 2.mysql的char类型取值范围0-255字节,varchar为0-65535字节 3.oracle的char类型 ...
- Saiku嵌入系统使用时传参数访问saiku(十六)
Saiku嵌入系统使用时传参数访问saiku Saiku通过iframe嵌入其他系统使用时,我们可以设定参数信息,然后根据url中参数对结果进行筛选哦. 这里我们实现的是根据日期字段进行范围查询,UR ...
- Redux源码学习笔记
https://github.com/reduxjs/redux 版本 4.0.0 先了解一下redux是怎么用的,此处摘抄自阮一峰老师的<Redux 入门教程> // Web 应用是一个 ...
- springcloud之服务注册与发现
本次分享的是关于springcloud服务注册与发现的内容,将通过分别搭建服务中心,服务注册,服务发现来说明:现在北京这边很多创业公司都开始往springcloud靠了,可能是由于文档和组件比较丰富的 ...
- es6学习笔记--模板字符串
这几天简单看了一下深入浅出es6这本书,感觉特实用,学习了一个新特性---模板字符串在项目开发中,拼接字符串是不可缺少的,动态创建dom元素以及js操作数据都要拼接字符串,在es6出来之前,我们都通常 ...
- ImportError: cannot import name UnrewindableBodyError
错误信息: File "/usr/lib/python2.7/site-packages/urllib3/util/__init__.py", line 4, in <mod ...
- Chapter 4 Invitations——19
After I hung up, I tried to concentrate on dinner — dicing the chicken especially; I didn't want to ...
- 爬虫协议 Tobots
一.简介 Robots 协议(也称为爬虫协议.机器人协议等)的全称是“网络爬虫排除标准”(Robots Exclusion Protocol),网站通过 Robots 协议告诉搜索引擎哪些页面可以抓取 ...
- 【Java基础】【22IO(其他流)&Properties】
22.01_IO流(序列流)(了解) 1.什么是序列流 序列流可以把多个字节输入流整合成一个, 从序列流中读取数据时, 将从被整合的第一个流开始读, 读完一个之后继续读第二个, 以此类推. 2.使用方 ...
- JVM(三)对象的生死判定和算法详解
好的文章是能把各个知识点,通过逻辑关系串连起来,让人豁然开朗的同时又记忆深刻. 导读:对象除了生死之外,还有其他状态吗?对象真正的死亡,难道只经历一次简单的判定?如何在垂死的边缘"拯救&qu ...