-2

我需要通过 SSHPASS(bash 脚本)将变量字符串附加到放置在远程机器中的现有文件中。

我试过

echo "$test" | sshpass -p $pass $host 'cat >> /remote/full/path/log/report.log'

sshpass -p $pass $host "echo $test" >> /remote/full/path/log/report.log

没有任何作用

4

3 回答 3

1

您需要将 'StrictHostkeyChecking=no' 选项添加到 ssh:

echo "$test" | sshpass -p $pass ssh - o StrictHostkeyChecking=0 $host 'cat >> /remote/full/path/log/report.log'

我不知道为什么会这样,但享受 bash 魔法。哈哈

在旁边:

如果您将要进入的用户的密码设置为 envar $SSHPASS 而不是 $pass,则可以使用 sshpass -e 选项。

SSHPASS=$pass
echo "$test" | sshpass -e ssh - o StrictHostkeyChecking=0 $host 'cat >> /remote/full/path/log/report.log'
于 2018-02-08T18:01:27.653 回答
0

我想通了:

sshpass -p $pass' ssh -o StrictHostKeyChecking=no $host "cd /full/path/ && echo $test >> /full/path/report.log"
于 2017-08-30T09:28:40.623 回答
0

鉴于在脚本中存储密码是一个很大的安全漏洞,这是 sshpass 语法:

sshpass -p 'your_pass_here' ssh user@domain 'df -h'
于 2017-08-30T09:28:52.467 回答