Total Pageviews

Wednesday, 16 December 2015

不加公私钥来实现脚本自动同步(sshpass)

在shell脚本中拷贝文件到远端服务器,可是每次提示我输入密码,很繁琐。通过公私钥的方法也挺麻烦。使用输入重定向也不行,因为scp直接从tty读取密码。有没有什么解决方法呢?
linux提供了另外一个工具sshpass,可以解决这个问题。按照man sshpass的讲法:
ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is getting the password from an interactive user.
使用方法:
sshpass -p "123456" scp list.txt user@10.148.6.99:/path/to/destination