非交互式ssh到服务器,但交互式

问题描述:

我这样理解所有使用ssh的安全风险,但我目前需要的是几行(bash)shell脚本能够登录到target服务器,做一个Foo命令,并回到源主机,是这样的:非交互式ssh到服务器,但交互式

while true 
do 
    ssh target foo # Here I get the prompt for a password which 
        # I would like to give non-interactively 
    sleep 1 
done 

不想使用SSH密钥的身份验证,因为我真正需要的是模拟1次(左右)交互式登录过程(但不是交互式!)。

您需要使用expect来编写脚本,例如perl

编辑:您也可以尝试直接在bash脚本expect

您必须编辑SSH服务器以允许仅基于密钥而不是密码进行登录。

试试看看this可以帮到你。

当然,如果你不能修改服务器的配置,你需要检查的交互,而不是其他的解决方案

sshpass旨在提供一个密码以编程SSH,。所以你可以用例如ssh target foo代替。 sshpass -f passwordfile ssh target foo