在写shell脚本时,需要登录到不同的服务器上执行相关命令,在未建立信任之前如何批量操作。
1、ssh 首次登录服务器时会提示RSA key fingerprint输入yes/no,可以通过下面的方法实现.
ssh test@192.168.1.3 -o "StrictHostKeyChecking no"
2、自动完成密码的输入,这个需要借助sshpass,要单独安装。
从命令行方式传递密码 -p指定密码
sshpass -p '123456' ssh user_name@host_ip
sshpass -p '123456' scp root@192.168.1.3:/opt/test.txt /tmp/