Net-OpenSSH
view release on metacpan or search on metacpan
lib/Net/OpenSSH.pm view on Meta::CPAN
errors. For instance:
my ($output, $errput) = $ssh->capture2({timeout => 1}, "find /");
$ssh->error and die "ssh failed: " . $ssh->error;
=head2 Net::OpenSSH methods
These are the methods provided by the package:
=over 4
=item Net::OpenSSH->new($host, %opts)
Creates a new SSH master connection
C<$host> can be a hostname or an IP address. It may also
contain the name of the user, her password and the TCP port
number where the server is listening:
my $ssh1 = Net::OpenSSH->new('jack@foo.bar.com');
my $ssh2 = Net::OpenSSH->new('jack:secret@foo.bar.com:10022');
my $ssh3 = Net::OpenSSH->new('jsmith@2001:db8::1428:57ab'); # IPv6
IPv6 addresses may optionally be enclosed in brackets:
my $ssh4 = Net::OpenSSH->new('jsmith@[::1]:1022');
This method always succeeds in returning a new object. Error checking
has to be performed explicitly afterwards:
my $ssh = Net::OpenSSH->new($host, %opts);
$ssh->error and die "Can't ssh to $host: " . $ssh->error;
If you have problems getting Net::OpenSSH to connect to the remote
host read the troubleshooting chapter near the end of this document.
Accepted options:
=over 4
=item user => $user_name
Login name
=item port => $port
TCP port number where the server is running
=item password => $password
User given password for authentication.
Note that using password authentication in automated scripts is a very
bad idea. When possible, you should use public key authentication
instead.
=item passphrase => $passphrase
X<passphrase>Uses given passphrase to open private key.
=item key_path => $private_key_path
Uses the key stored on the given file path for authentication.
=item gateway => $gateway
If the given argument is a gateway object as returned by
L<Net::OpenSSH::Gateway/find_gateway> method, use it to connect to
the remote host.
If it is a hash reference, call the C<find_gateway> method first.
For instance, the following code fragments are equivalent:
my $gateway = Net::OpenSSH::Gateway->find_gateway(
proxy => 'http://proxy.corporate.com');
$ssh = Net::OpenSSH->new($host, gateway => $gateway);
and
$ssh = Net::OpenSSH->new($host,
gateway => { proxy => 'http://proxy.corporate.com'});
=item proxy_command => $proxy_command
Use the given command to establish the connection to the remote host
(see C<ProxyCommand> on L<ssh_config(5)>).
=item batch_mode => 1
Disables querying the user for password and passphrases.
=item ctl_dir => $path
Directory where the SSH master control socket will be created.
This directory and its parents must be writable only by the current
effective user or root, otherwise the connection will be aborted to
avoid insecure operation.
By default C<~/.libnet-openssh-perl> is used.
=item ctl_path => $path
Path to the SSH master control socket.
Usually this option should be avoided as the module is able to pick an unused
socket path by itself. An exception to that rule is when the C<external_master>
feature is enabled.
Note that the length of the path is usually limited to between 92 and 108 bytes,
depending of the underlying operating system.
=item ssh_cmd => $cmd
Name or full path to OpenSSH C<ssh> binary. For instance:
my $ssh = Net::OpenSSH->new($host, ssh_cmd => '/opt/OpenSSH/bin/ssh');
=item scp_cmd => $cmd
( run in 1.808 second using v1.01-cache-2.11-cpan-39bf76dae61 )