[root@kvm8 ~]# yum install -y sshpass
[root@kvm8 ~]# ssh kvm7.deyu.wang Last login: Tue Feb 4 19:49:12 2014 from deyu.wang [root@kvm7 ~]# mv .ssh/authorized_keys /tmp [root@kvm7 ~]# exit logout Connection to kvm7.deyu.wang closed.
known_hosts
會記錄曾經連線過的信任主機,若連線主機重新安裝或更換 ip,其 host key 不同,ssh 會產生警告訊息,要求確認並刪除在 known_hosts
中的記錄,才能連線。選項 -o StrictHostKeyChecking=no
就是不進行 host key 的檢查,以避免此中斷程式的動作。
[root@kvm8 ~]# sshpass -p123qwe ssh -o StrictHostKeyChecking=no kvm7.deyu.wang "echo aaaa > /root/abc"
[root@kvm8 ~]# echo bbbb > b.txt [root@kvm8 ~]# rsync -av -e "sshpass -p123qwe ssh" b.txt kvm7.deyu.wang: sending incremental file list b.txt sent 78 bytes received 31 bytes 218.00 bytes/sec
[root@kvm7 ~]# cat abc aaaa [root@kvm7 ~]# cat b.txt bbbb