目的:新建管理机,为了实现批量管理主机,设置密匙登陆
原理:.通过密钥登陆,可以不用密码
操作过程:
1.生成密匙
ssh-keygen
2.查看密匙
ls ~/.ssh/
有私匙id_rsa公匙id_rsa.pub
3.单个发送公匙
ssh-copy-id -i ~/.ssh/id_rsa.pub 用户名@用户ip地址
例:ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.100
4.批量推送公匙
先安装expect:yum -y install expect
[root@localhost wang]# vim sshCopyId.sh
#!/bin/bash
for i in 192.168.100.{172..176} #定义i变量,逐个查看
do
password="jianchi"
/usr/bin/expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$i
expect {
"*(yes/no)" { send "yes
";exp_continue }
"*password" { send "$password
"; exp_continue }
}
expect eof"
done