Linux 下方便的ssh非交互工具sshpass的安装与使用
1. 下载sshpass包并安装
wget https://mirrors.ustc.edu.cn/epel/6/x86_64/sshpass-1.06-1.el6.x86_64.rpm rpm -ivh sshpass-1.06-1.el6.x86_64.rpm
2. 使用sshpass实现自动ssh和自动scp
sshpass -p 'password' ssh root@192.168.1.5 sshpass -p 'password' scp test.txt root@192.168.1.5:/tmp/
3. 如果遇到需要yes/no选项的时候,可以对ssh命令和scp命令加参以避免
sshpass -p 'password' ssh -o StrictHostKeychecking=no root@192.168.1.5 sshpass -p 'password' scp -o StrictHostKeychecking=no test.txt root@192.168.1.5:/tmp/