SSH批量管理
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
1.ssh-keygen非交互式创建秘钥对:
具体命令:ssh-keygen -f ~/.ssh/id_rsa -P '' -q
安装yum源
wget -P /etc/yum.repo.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum clean all
yum makecache
yum -y install sshpass
2.ssh-copy-id不需要提示yes/no分发秘钥
具体命令:ssh-copy-id -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no 192.168.230.131
3.sshpass工具:指定密码非人工交互分发秘钥
sshpass -Tcs6688.cn ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 192.168.230.131
4.测试
[root@linux-node1 ~]# ssh 192.168.230.131 "ifconfig eth0"
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.230.131 netmask 255.255.255.0 broadcast 192.168.230.255
inet6 fe80::20c:29ff:fe06:e26f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:06:e2:6f txqueuelen 1000 (Ethernet)
RX packets 52509 bytes 3349832 (3.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1331 bytes 189636 (185.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
5.如果有多台可以用脚本去批量添加分发
#!/bin/bash
#yum install sshpass -y
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
for ip in 131 132
do
sshpass -pTcs6688.cn ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 192.168.230.$ip
done