Rex-LibSSH
view release on metacpan or search on metacpan
## Interface Modules
- `Rex::Interface::Connection::LibSSH` â SSH session lifecycle via Net::LibSSH
- `Rex::Interface::Exec::LibSSH` â command execution via SSH exec channels
- `Rex::Interface::Fs::LibSSH` â `is_file`, `stat`, `ls`, etc. via exec
- `Rex::Interface::File::LibSSH` â file upload/download via `cat`/heredoc exec
## Key Details
- `strict_hostkeycheck => 0` by default (non-interactive deploys)
- Public key auth via `Rex::Config->set_private_key` / `set_public_key`
- No SFTP subsystem needed on remote host
- Used by Rex::Rancher and Rex::GPU for Hetzner dedicated server deployments
## Dependencies
- `Net::LibSSH` (XS binding for libssh)
- `Alien::libssh` (provides the libssh C library)
- `Rex` (framework)
## Build
lib/Rex/Interface/Connection/LibSSH.pm view on Meta::CPAN
}
sub connect {
my ( $self, %opt ) = @_;
my $server = $opt{server};
my $port = $opt{port} || Rex::Config->get_port( server => $server ) || 22;
my $timeout = $opt{timeout} || Rex::Config->get_timeout( server => $server ) || 10;
my $user = $opt{user};
my $password = $opt{password};
my $privkey = $opt{private_key};
my $auth = $opt{auth_type} // 'key';
$self->{server} = $server;
$self->{is_sudo} = $opt{sudo};
$self->{__auth_info__} = \%opt;
( $server, $port ) = Rex::Helper::IP::get_server_and_port( $server, $port );
Rex::Logger::debug("LibSSH: connecting to $server:$port as $user");
lib/Rex/LibSSH.pm view on Meta::CPAN
Rex's interface dispatch will automatically load
L<Rex::Interface::Connection::LibSSH>,
L<Rex::Interface::Exec::LibSSH>,
L<Rex::Interface::Fs::LibSSH>, and
L<Rex::Interface::File::LibSSH>.
=head2 Authentication
Supports public key authentication:
Rex::Config->set_private_key('/home/user/.ssh/id_ed25519');
Rex::Config->set_public_key('/home/user/.ssh/id_ed25519.pub');
Or pass keys directly to C<Rex::connect>:
Rex::connect(
server => '10.0.0.1',
user => 'root',
private_key => '/path/to/key',
public_key => '/path/to/key.pub',
auth_type => 'key',
);
Host key checking is disabled by default (C<strict_hostkeycheck =E<gt> 0>)
to avoid blocking non-interactive deploys. To enable it, pass the option
when connecting:
Rex::connect(
server => '10.0.0.1',
t/01-rex-integration.t view on Meta::CPAN
use Rex -feature => ['1.4'];
use Rex::Group::Entry::Server;
use Rex::Commands::Run;
use Rex::Commands::Fs;
use Rex::Commands::File;
use Rex::Config;
set connection => 'LibSSH';
Rex::Config->set_user( scalar getpwuid($<) );
Rex::Config->set_private_key( $srv->client_key );
Rex::Config->set_public_key( $srv->client_key . '.pub' );
Rex::connect(
server => $srv->host,
port => $srv->port,
user => scalar( getpwuid($<) ),
private_key => $srv->client_key,
public_key => $srv->client_key . '.pub',
auth_type => 'key',
);
# --- run ---
my $out = run 'echo hello';
chomp $out;
is $out, 'hello', 'run echo works';
# --- is_file / is_dir ---
( run in 0.859 second using v1.01-cache-2.11-cpan-39bf76dae61 )