【问题标题】:Remote ssh twice远程 ssh 两次
【发布时间】:2023-03-25 05:57:01
【问题描述】:

我正在尝试通过 ssh 远程执行命令。 它是 2 倍远程(2 级深)。 从我的主机,我 ssh 到连接到 target2 的 target1。 我需要在 target2 上执行的命令。 从主机到 target2 没有直接连接。 前任: ssh root@target1 -t "ssh root@target2 -t "cat /usr/value"" 上面的命令有效。 ssh root@target1 -t "ssh root@target2 -t "echo 1 > /usr/value"" 该命令不起作用。我得到“没有这样的文件或目录”

【问题讨论】:

    标签: ssh


    【解决方案1】:

    您正在尝试使用 shell 功能(重定向)而不是命令,因此请通过 shell 运行它(注意:引用变得棘手):

    ssh -t root@target1 'ssh -t root@target2 /bin/bash -c \"echo 1 > /usr/value\"'
    

    我建议你研究 ssh_config 的手册页。例如,这样:

    Host target2
       User root
       ProxyJump root@target1
    

    你上面的命令是:

    ssh -t target2 '/bin/bash -c "echo 1 > /usr/value"'
    

    下一步是使用 ansible(或类似的)进行系统更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 2011-07-21
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多