免密码登陆
1、在管理机上面生成密钥:ssh-keygen -t rsa 文件生成目录为: [root@localhost .ssh]# pwd /root/.ssh [root@localhost .ssh]# ls id_rsa id_rsa.pub known_hosts 文件另存 cp id_rsa.pub ./id_rsa.pub_bak 将备份文件改名: mv id_rsa.pub_bak ./authorized_keys
2、在需要管控的机器上面创建目录 mkdir /root/.ssh chmod 700 /root/.ssh
3、将文件authorized_keys复制到需要管控的机器上面 scp authorized_keys root@192.168.11.2:/root/.ssh/authorized_keys scp authorized_keys root@192.168.11.3:/root/.ssh/authorized_keys
4、关机脚本: #!/bin/bash ssh -t 192.168.11.2 “echo “123456” | sudo -S shutdown -h now” ssh -t 192.168.11.3 “echo “123456” | sudo -S shutdown -h now” –192.168.11.2/3为主机IP –123456为开机密码
|