#yyds干货盘点#ssh批量管理主机
Posted 王华_linux
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#yyds干货盘点#ssh批量管理主机相关的知识,希望对你有一定的参考价值。
1. #不登录对方的主机在对方的主机上执行对方主机上的脚本
[root@c7-167 ~]# vim /data/hostname.sh
[root@c7-167 ~]# chmod +x /data/hostname.sh
[root@c7-167 ~]# cat /data/hostname.sh
hostname -I
[root@C8-28 ~]# ssh 10.0.0.167 -p 2222 /data/hostname.sh
root@10.0.0.167s password:
10.0.0.167
2 . #不登录对方的主机在对方的主机上执行自己机器上的脚本
[root@c7-167 ~]# ssh 10.0.0.28 bash </data/hostname.sh
root@10.0.0.28s password:
10.0.0.28
[root@c7-167 ~]# ssh 10.0.0.6 bash </data/hostname.sh
The authenticity of host 10.0.0.6 (10.0.0.6) cant be established.
RSA key fingerprint is e0:21:c2:a3:83:1b:61:67:55:ea:3d:76:4d:ca:16:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 10.0.0.6 (RSA) to the list of known hosts.
root@10.0.0.6s password:
10.0.0.6
[root@c7-167 ~]# ssh 10.0.0.177 bash </data/hostname.sh
root@10.0.0.177s password:
10.0.0.177
3. 批量管理主机
[root@c7-167 ~]# cat host.txt
10.0.0.177
10.0.0.28
[root@c7-167 ~]# while read ip;do ssh $ip bash </data/hostname.sh ;done <host.txt
10.0.0.177
10.0.0.28
[root@c7-177 ~]# rm -rf .ssh/
[root@c7-167 ~]# scp -p .ssh/id_rsa 10.0.0.177:/root/.ssh
root@10.0.0.177s password:
id_rsa 100% 1679 1.6KB/s 00:00
[root@c7-167 ~]#
[root@c7-177 ~]# ll /root/.ssh/
total 4
-rw-r--r--. 1 root root 179 Dec 26 07:08 known_hosts
[root@c7-167 ~]# scp -p .ssh/id_rsa 10.0.0.177:/root/.ssh/
root@10.0.0.177s password:
id_rsa 100% 1679 1.6KB/s 00:00
[root@c7-167 ~]#
[root@c7-177 ~]# ll /root/.ssh/
total 8
-rw#yyds干货盘点#通过 SSH 管理远程连接Git SSH Key 生成并添加到github/gitee步骤#yyds干货盘点#