gpt4 book ai didi

perl - Net::SSH::Perl 使用转发的 SSH key

转载 作者:行者123 更新时间:2023-12-02 04:57:53 25 4
gpt4 key购买 nike

我正在尝试使用 Net::SSH::Perl 编写 perl 脚本

目前非常简单,因为我只想通过 ssh 在目录中执行 ls 操作。

#!/usr/bin/perl

use Net::SSH::Perl;

@KEYFILE = ("/user/.ssh/id_rsa");
$ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)

my $host = "hostname";
my $user = "user";

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)
#-- authenticate
$ssh->login($user);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/user/");

这可行,但唯一的问题是,我需要跳过堡垒服务器才能运行命令。我将我的私钥转发到堡垒,但我遇到的问题是如何在 Perl 中使用转发的 key ,而不是使用必须位于服务器上的 key 。

这可能吗?

谢谢

最佳答案

连接到堡垒服务器时必须启用代理转发:

my $ssh = Net::SSH::Perl->new(
$host,
debug => 1,
identity_files => \@KEYFILE,
options => [
'ForwardAgent yes',
],
);

有关其他 ssh Perl 模块及其优缺点,请参阅 Net::OpenSSH vs Net::SSH:: modules .

关于perl - Net::SSH::Perl 使用转发的 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15968988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com