【问题标题】:Performing second SSH within SSH in perl在 perl 中的 SSH 中执行第二个 SSH
【发布时间】:2016-07-08 21:49:22
【问题描述】:

我必须从我使用 Net::SSH::Perl 登录的远程计算机执行 SSH,即下面代码中传递给 $ssh->cmd 的“cmd”是另一个 SSH(比如用户名@主机名)。有没有办法传递第二个 SSH 的密码,然后在第二个远程机器上执行命令。 另外,我不能使用 ssh 密钥对登录或 sshpass 之类的工具。有人可以帮忙吗?

use Net::SSH::Perl;

    my $hostname = "hostname";
    my $username = "username";
    my $password = "password";

    my $cmd = <command to be executed on remote machine>;

    my $ssh = Net::SSH::Perl->new("$hostname", debug=>0);
    $ssh->login("$username","$password");
    my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd");
    print $stdout;

【问题讨论】:

标签: linux git perl ssh


【解决方案1】:

Net::SSH::Perl 受到严重限制。我建议您尽可能使用Net::OpenSSH。它支持代理命令和隧道,使其易于使用jump host

如果 Net::SSH 是您唯一的选择,那么恐怕唯一的方法就是使用某种类似期望的行为,例如网络::SSH::期望。

【讨论】:

    猜你喜欢
    • 2012-07-19
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2011-07-29
    相关资源
    最近更新 更多