当前位置:网站首页>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
边栏推荐
- 【ML】李宏毅三:梯度下降&分类(高斯分布)
- 一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
- 基于Pyqt5工具栏按钮可实现界面切换-1
- Master the development of facial expression recognition based on deep learning (based on paddlepaddle)
- MFC file operation
- MySQL Foundation
- Leetcode relaxation question - day of the week
- Arduino - character judgment function
- JDBC教程
- PR FAQ, what about PR preview video card?
猜你喜欢
随机推荐
MFC gets the current time
JDBC practice cases
[OJ] intersection of two arrays (set, hash mapping...)
基于OpenCV实现口罩识别
Brief introduction to common sense of Zhongtai
[Verilog tutorial]
(stinger) use pystinger Socks4 to go online and not go out of the network host
购买完域名之后能干什么事儿?
基于Pyqt5工具栏按钮可实现界面切换-1
Go project operation method
How much do you know about synchronized?
Wechat applet basic learning (wxss)
php 获取真实ip
程序分析与优化 - 9 附录 XLA的缓冲区指派
Mapper agent development
Bean加载控制
Linux 下安装 redis
RuntimeError: no valid convolution algorithms available in CuDNN
跨境电商如何通过打好数据底座,实现低成本稳步增长
[array] binary search