当前位置:网站首页>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
边栏推荐
- Integration of revolution and batch normalization
- 67页新型智慧城市整体规划建设方案(附下载)
- Develop knowledge points
- Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup
- Go project operation method
- JSON数据传递参数
- leetcode 650. 2 keys keyboard with only two keys (medium)
- C MVC creates a view to get rid of the influence of layout
- MySQL Foundation
- Speech recognition Series 1: speech recognition overview
猜你喜欢

Yolox enhanced feature extraction network panet analysis

基于Pyqt5工具栏按钮可实现界面切换-2

"A good programmer is worth five ordinary programmers!"

Print out mode of go

Load balancing cluster (LBC)

Mapper agent development

Data set - fault diagnosis: various data and data description of bearings of Western Reserve University

MarkDown基本语法

Program analysis and Optimization - 9 appendix XLA buffer assignment

Wechat applet basic learning (wxss)
随机推荐
(毒刺)利用Pystinger Socks4上线不出网主机
[array] binary search
Arduino - 字符判断函数
开发知识点
Sourcetree details
JDBC教程
接口自动化覆盖率统计——Jacoco使用
Go project operation method
PHP get real IP
Master the development of facial expression recognition based on deep learning (based on paddlepaddle)
How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
JDBC tutorial
Request and response
CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)
[analysis of STL source code] imitation function (to be supplemented)
Bean load control
All things work together, and I will review oceanbase's practice in government and enterprise industry
List of major chip Enterprises
Mapper agent development
[OJ] intersection of two arrays (set, hash mapping...)