当 scp 从一台服务器复制到另一台服务器时,将带有 sshpass 的密码传递给两台服务器

Pass password with sshpass to both servers when scp copying from one server to another

我正在使用 scp 将文件从一台服务器复制到另一台服务器。两个服务器都需要使用 sshpass 传递密码,因此我需要在同一个命令中使用 sshpass 两次。请注意,我使用 -3 标志是因为服务器 foo 无法直接与服务器 boo 通信。 我试过 sshpass -p 'foo' scp -3 foo@foo.com:/home/foo/foo.txt sshpass -p 'boo' boo@boo.com:/home/boo/ 但它不起作用,没有错误消息,只是没有复制文件。有办法实现吗?

注意:请不要使用密钥对建议答案,我想传入密码而不是使用密钥(或提示用户输入密码),我明知道全系统可见,不安全,还是想做

这是不可能的。

根据scp manual:

  • -3

    Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter and selects batch mode for the second host, since scp cannot ask for passwords or passphrases for both hosts.

并根据ssh_config manual:

  • BatchMode

    If set to yes, user interaction such as password prompts and host key confirmation requests will be disabled. This option is useful in scripts and other batch jobs where no user is present to interact with ssh(1). The argument must be yes or no (the default).