通过多个 ssh 隧道复制文件

通过多个 ssh 隧道复制文件

我遇到了一个很尴尬的情况,我需要通过多个隧道连接到一台机器。下面详细说明原因,但此命令适用于 ssh 进入server2

ssh -A -t [email protected] ssh -A -t [email protected] ssh -A -t [email protected] ssh -A [email protected]

(为简洁起见,该命令现在是$ssh_cmd)如何使用类似的隧道设置将文件复制到该机器/从该机器复制文件?例如,我尝试过:

rsync --rsh=ssh -e "$ssh_cmd" [email protected]:filename .

即使删除了-t,它仍然会失败,因为它没有给我机会输入密码:

debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.

那么我该如何设置这个隧道复制命令?

额外详细信息:

  • portal1 阻止代理命令,这需要额外的一次跳转,并防止方便的.ssh/config黑客攻击
  • 身份验证失败似乎至少让我被封禁过一次

编辑:larsks 建议使用基于密钥的身份验证,这在一定程度上有效,但随后失败了:

debug1: Host 'server2.host2.org' is known and matches the ECDSA host key.
debug1: Found key in /home/username2/.ssh/known_hosts:3
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.

我不明白;如果它找到了钥匙为什么不使用它?

答案1

答案至少部分是我的rsync命令错误。上面的 ssh 命令应该排除对用户名/主机的最后引用,即:

ssh -A -t [email protected] ssh -A -t [email protected] ssh -A -t [email protected] ssh -A

而不是上面显示的命令。这在调试输出中很明显:

debug1: Sending command: ssh -Av [email protected] -l username2 server2.host2.org rsync --server --sender -vvulogDtprCe.iLs . filename
bash: server2.host2.org: command not found

其中重复指定了服务器,这样服务器名称就可以被远程解释为命令。

对于认证失败,使用基于密钥的认证解决了问题。

我还添加了-o StrictHostKeyChecking=no处理主机密钥验证失败的内容。

相关内容