第一步:生成私钥**
[[email protected] ~]# ssh-****** -t rsa
[[email protected] ~]# ls /root/.ssh
id_rsa (私钥) id_rsa.pub(公钥) known_hosts
第二步:拷贝公钥到另一台主机
[[email protected] .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub -p 18999 [email protected]
第三步:测试,如果/etc/hosts文件都加了ip和主机名的快速解析的话,可以直接链接主机名
[[email protected] .ssh]# ssh -p '18999' '[email protected]'
Last login: Thu Oct 24 02:39:49 2019 from 59.37.6.50
[[email protected] ~]# exit
四:免**远程执行脚本
[[email protected] ~]# cat ssh.sh
#!/bin/bash
ssh -p 18999 [email protected] <<EOF
rm -rf /root/test.txt
ls /root/
exit
EOF