当前位置:网站首页>S12. Verify multi host SSH mutual access script based on key
S12. Verify multi host SSH mutual access script based on key
2022-07-02 23:47:00 【Raymond999999】
be based on key Verify multi host ssh visit
[[email protected] ~]# cat ssh_key.sh
#!/bin/bash
#
#**********************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2021-12-20
#FileName: ssh_key.sh
#URL: raymond.blog.csdn.net
#Description: ssh_key for CentOS 7/8 & Ubuntu 18.04/24.04 & Rocky 8
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
# be based on key Verify multi host ssh Visit each other
COLOR="echo -e \\033[01;31m"
END='\033[0m'
PASS=123456
# Set the last address of the network segment ,4-255 Between , The smaller the scan, the faster
END=254
IP=`ip a s eth0 | awk -F'[ /]+' 'NR==3{print $3}'`
NET=${IP%.*}.
os(){
OS_ID=`sed -rn '/^NAME=/[email protected]*="([[:alpha:]]+).*"[email protected]\1@p' /etc/os-release`
}
ssh_key_push(){
rm -f /root/.ssh/id_rsa
[ -e ./SCANIP.log ] && rm -f SCANIP.log
for((i=3;i<="$END";i++));do
ping -c 1 -w 1 ${NET}${i} &> /dev/null && echo "${NET}${i}" >> SCANIP.log &
done
wait
ssh-keygen -f /root/.ssh/id_rsa -P '' &> /dev/null
if [ ${OS_ID} == "CentOS" -o ${OS_ID} == "Rocky" ] &> /dev/null;then
rpm -q sshpass &> /dev/null || {
${COLOR}" install sshpass software package "${END};yum -y install sshpass &> /dev/null; }
else
dpkg -S sshpass &> /dev/null || {
${COLOR}" install sshpass software package "${END};apt -y install sshpass &> /dev/null; }
fi
sshpass -p ${PASS} ssh-copy-id -o StrictHostKeyChecking=no ${IP}
AliveIP=(`cat SCANIP.log`)
for n in ${AliveIP[*]};do
sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh [email protected]${n}:
done
# hold .ssh/known_hosts Copy to all hosts , So that they don't need to enter carriage return when they visit each other for the first time
for n in ${AliveIP[*]};do
scp /root/.ssh/known_hosts ${n}:.ssh/
done
}
main(){
os
ssh_key_push
}
main
边栏推荐
- 数据集-故障诊断:西储大学轴承的各项数据以及数据说明
- What is the official website address of e-mail? Explanation of the login entry of the official website address of enterprise e-mail
- 67页新型智慧城市整体规划建设方案(附下载)
- Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
- yolov5test. Py comment
- Go basic anonymous variable
- 简述中台的常识
- 开发知识点
- yolov5detect. Py comment
- "A good programmer is worth five ordinary programmers!"
猜你喜欢
Dishes launcher small green program and directory management (efficiency tool)
JSON data transfer parameters
MySQL Foundation
【STL源码剖析】仿函数(待补充)
Interface switching based on pyqt5 toolbar button -1
实用系列丨免费可商用视频素材库
How much do you know about synchronized?
基于FPGA的VGA协议实现
[analysis of STL source code] imitation function (to be supplemented)
Where is the win11 microphone test? Win11 method of testing microphone
随机推荐
Load balancing cluster (LBC)
Agnosticism and practice makes perfect
流媒体技术优化
Difference between NVIDIA n card and amda card
[live broadcast appointment] database obcp certification comprehensive upgrade open class
C# MVC创建一个视图摆脱布局的影响
Installing redis under Linux
理想汽车×OceanBase:当造车新势力遇上数据库新势力
返回二叉树两个节点间的最大距离
Leetcode relaxation question - day of the week
基于OpenCV实现口罩识别
公司里只有一个测试是什么体验?听听他们怎么说吧
How much do you know about synchronized?
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
实用系列丨免费可商用视频素材库
[proteus simulation] 51 MCU +lcd12864 push box game
Judge whether the binary tree is full binary tree
Use of cocospods
Request and response