.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::OpenSSH 3" .TH Net::OpenSSH 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Net::OpenSSH \- Perl SSH client package implemented on top of OpenSSH .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Net::OpenSSH; \& \& my $ssh = Net::OpenSSH\->new($host); \& $ssh\->error and \& die "Couldn\*(Aqt establish SSH connection: ". $ssh\->error; \& \& $ssh\->system("ls /tmp") or \& die "remote command failed: " . $ssh\->error; \& \& my @ls = $ssh\->capture("ls"); \& $ssh\->error and \& die "remote ls command failed: " . $ssh\->error; \& \& my ($out, $err) = $ssh\->capture2("find /root"); \& $ssh\->error and \& die "remote find command failed: " . $ssh\->error; \& \& my ($rin, $pid) = $ssh\->pipe_in("cat >/tmp/foo") or \& die "pipe_in method failed: " . $ssh\->error; \& \& print $rin "hello\en"; \& close $rin; \& \& my ($rout, $pid) = $ssh\->pipe_out("cat /tmp/foo") or \& die "pipe_out method failed: " . $ssh\->error; \& \& while (<$rout>) { print } \& close $rout; \& \& my ($in, $out ,$pid) = $ssh\->open2("foo"); \& my ($pty, $pid) = $ssh\->open2pty("foo"); \& my ($in, $out, $err, $pid) = $ssh\->open3("foo"); \& my ($pty, $err, $pid) = $ssh\->open3pty("login"); \& \& my $sftp = $ssh\->sftp(); \& $sftp\->error and die "SFTP failed: " . $sftp\->error; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Net::OpenSSH is a secure shell client package implemented on top of OpenSSH binary client (\f(CW\*(C`ssh\*(C'\fR). .SS "Under the hood" .IX Subsection "Under the hood" This package is implemented around the multiplexing feature found in later versions of OpenSSH. That feature allows one to run several sessions over a single SSH connection (OpenSSH 4.1 was the first one to provide all the required functionality). .PP When a new Net::OpenSSH object is created, the OpenSSH \f(CW\*(C`ssh\*(C'\fR client is run in master mode, establishing a persistent (for the lifetime of the object) connection to the server. .PP Then, every time a new operation is requested a new \f(CW\*(C`ssh\*(C'\fR process is started in slave mode, effectively reusing the master SSH connection to send the request to the remote side. .SS "Net::OpenSSH Vs. Net::SSH::.* modules" .IX Subsection "Net::OpenSSH Vs. Net::SSH::.* modules" Why should you use Net::OpenSSH instead of any of the other Perl SSH clients available? .PP Well, this is my (biased) opinion: .PP Net::SSH::Perl is not well maintained nowadays (update: a new maintainer has stepped in so this situation could change!!!), requires a bunch of modules (some of them very difficult to install) to be acceptably efficient and has an API that is limited in some ways. .PP Net::SSH2 is much better than Net::SSH::Perl, but not completely stable yet. It can be very difficult to install on some specific operating systems and its API is also limited, in the same way as Net::SSH::Perl. .PP Using Net::SSH::Expect, in general, is a bad idea. Handling interaction with a shell via Expect in a generic way just can not be reliably done. .PP Net::SSH is just a wrapper around any SSH binary commands available on the machine. It can be very slow as they establish a new SSH connection for every operation performed. .PP In comparison, Net::OpenSSH is a pure perl module that does not have any mandatory dependencies (obviously, besides requiring OpenSSH binaries). .PP Net::OpenSSH has a very perlish interface. Most operations are performed in a fashion very similar to that of the Perl builtins and common modules (e.g. IPC::Open2). .PP It is also very fast. The overhead introduced by launching a new ssh process for every operation is not appreciable (at least on my Linux box). The bottleneck is the latency intrinsic to the protocol, so Net::OpenSSH is probably as fast as an SSH client can be. .PP Being based on OpenSSH is also an advantage: a proved, stable, secure (to paranoid levels), inseparably and well maintained implementation of the SSH protocol is used. .PP On the other hand, Net::OpenSSH does not work on Windows, not even under Cygwin. .PP Net::OpenSSH specifically requires the OpenSSH SSH client (AFAIK, the multiplexing feature is not available from any other SSH client). However, note that it will interact with any server software, not just servers running OpenSSH \f(CW\*(C`sshd\*(C'\fR. .PP For password authentication, IO::Pty has to be installed. Other modules and binaries are also required to implement specific functionality (for instance Net::SFTP::Foreign, Expect or \&\fBrsync\fR\|(1)). .PP Net::OpenSSH and Net::SSH2 do not support version 1 of the SSH protocol. .SH API .IX Header "API" .SS "Optional arguments" .IX Subsection "Optional arguments" Almost all methods in this package accept as first argument an optional reference to a hash containing parameters (\f(CW\*(C`\e%opts\*(C'\fR). For instance, these two method calls are equivalent: .PP .Vb 2 \& my $out1 = $ssh\->capture(@cmd); \& my $out2 = $ssh\->capture({}, @cmd); .Ve .SS "Error handling" .IX Subsection "Error handling" Most methods return undef (or an empty list) to indicate failure. .PP The "error" method can always be used to explicitly check for errors. For instance: .PP .Vb 2 \& my ($output, $errput) = $ssh\->capture2({timeout => 1}, "find /"); \& $ssh\->error and die "ssh failed: " . $ssh\->error; .Ve .SS "Net::OpenSSH methods" .IX Subsection "Net::OpenSSH methods" These are the methods provided by the package: .ie n .IP "Net::OpenSSH\->new($host, %opts)" 4 .el .IP "Net::OpenSSH\->new($host, \f(CW%opts\fR)" 4 .IX Item "Net::OpenSSH->new($host, %opts)" Creates a new SSH master connection .Sp \&\f(CW$host\fR 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: .Sp .Vb 3 \& my $ssh1 = Net::OpenSSH\->new(\*(Aqjack@foo.bar.com\*(Aq); \& my $ssh2 = Net::OpenSSH\->new(\*(Aqjack:secret@foo.bar.com:10022\*(Aq); \& my $ssh3 = Net::OpenSSH\->new(\*(Aqjsmith@2001:db8::1428:57ab\*(Aq); # IPv6 .Ve .Sp IPv6 addresses may optionally be enclosed in brackets: .Sp .Vb 1 \& my $ssh4 = Net::OpenSSH\->new(\*(Aqjsmith@[::1]:1022\*(Aq); .Ve .Sp This method always succeeds in returning a new object. Error checking has to be performed explicitly afterwards: .Sp .Vb 2 \& my $ssh = Net::OpenSSH\->new($host, %opts); \& $ssh\->error and die "Can\*(Aqt ssh to $host: " . $ssh\->error; .Ve .Sp If you have problems getting Net::OpenSSH to connect to the remote host read the troubleshooting chapter near the end of this document. .Sp Accepted options: .RS 4 .ie n .IP "user => $user_name" 4 .el .IP "user => \f(CW$user_name\fR" 4 .IX Item "user => $user_name" Login name .ie n .IP "port => $port" 4 .el .IP "port => \f(CW$port\fR" 4 .IX Item "port => $port" TCP port number where the server is running .ie n .IP "password => $password" 4 .el .IP "password => \f(CW$password\fR" 4 .IX Item "password => $password" User given password for authentication. .Sp Note that using password authentication in automated scripts is a very bad idea. When possible, you should use public key authentication instead. .ie n .IP "passphrase => $passphrase" 4 .el .IP "passphrase => \f(CW$passphrase\fR" 4 .IX Item "passphrase => $passphrase" Uses given passphrase to open private key. .IX Xref "passphrase" .ie n .IP "key_path => $private_key_path" 4 .el .IP "key_path => \f(CW$private_key_path\fR" 4 .IX Item "key_path => $private_key_path" Uses the key stored on the given file path for authentication. .ie n .IP "gateway => $gateway" 4 .el .IP "gateway => \f(CW$gateway\fR" 4 .IX Item "gateway => $gateway" If the given argument is a gateway object as returned by "find_gateway" in Net::OpenSSH::Gateway method, use it to connect to the remote host. .Sp If it is a hash reference, call the \f(CW\*(C`find_gateway\*(C'\fR method first. .Sp For instance, the following code fragments are equivalent: .Sp .Vb 3 \& my $gateway = Net::OpenSSH::Gateway\->find_gateway( \& proxy => \*(Aqhttp://proxy.corporate.com\*(Aq); \& $ssh = Net::OpenSSH\->new($host, gateway => $gateway); .Ve .Sp and .Sp .Vb 2 \& $ssh = Net::OpenSSH\->new($host, \& gateway => { proxy => \*(Aqhttp://proxy.corporate.com\*(Aq}); .Ve .ie n .IP "proxy_command => $proxy_command" 4 .el .IP "proxy_command => \f(CW$proxy_command\fR" 4 .IX Item "proxy_command => $proxy_command" Use the given command to establish the connection to the remote host (see \f(CW\*(C`ProxyCommand\*(C'\fR on \fBssh_config\fR\|(5)). .IP "batch_mode => 1" 4 .IX Item "batch_mode => 1" Disables querying the user for password and passphrases. .ie n .IP "ctl_dir => $path" 4 .el .IP "ctl_dir => \f(CW$path\fR" 4 .IX Item "ctl_dir => $path" Directory where the SSH master control socket will be created. .Sp 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. .Sp By default \f(CW\*(C`~/.libnet\-openssh\-perl\*(C'\fR is used. .ie n .IP "ctl_path => $path" 4 .el .IP "ctl_path => \f(CW$path\fR" 4 .IX Item "ctl_path => $path" Path to the SSH master control socket. .Sp 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 \f(CW\*(C`external_master\*(C'\fR feature is enabled. .Sp Note that the length of the path is usually limited to between 92 and 108 bytes, depending of the underlying operating system. .ie n .IP "ssh_cmd => $cmd" 4 .el .IP "ssh_cmd => \f(CW$cmd\fR" 4 .IX Item "ssh_cmd => $cmd" Name or full path to OpenSSH \f(CW\*(C`ssh\*(C'\fR binary. For instance: .Sp .Vb 1 \& my $ssh = Net::OpenSSH\->new($host, ssh_cmd => \*(Aq/opt/OpenSSH/bin/ssh\*(Aq); .Ve .ie n .IP "scp_cmd => $cmd" 4 .el .IP "scp_cmd => \f(CW$cmd\fR" 4 .IX Item "scp_cmd => $cmd" Name or full path to OpenSSH \f(CW\*(C`scp\*(C'\fR binary. .Sp By default it is inferred from the \f(CW\*(C`ssh\*(C'\fR one. .ie n .IP "rsync_cmd => $cmd" 4 .el .IP "rsync_cmd => \f(CW$cmd\fR" 4 .IX Item "rsync_cmd => $cmd" Name or full path to \f(CW\*(C`rsync\*(C'\fR binary. Defaults to \f(CW\*(C`rsync\*(C'\fR. .ie n .IP "remote_shell => $name" 4 .el .IP "remote_shell => \f(CW$name\fR" 4 .IX Item "remote_shell => $name" Name of the remote shell. Used to select the argument quoter backend. .ie n .IP "timeout => $timeout" 4 .el .IP "timeout => \f(CW$timeout\fR" 4 .IX Item "timeout => $timeout" Maximum acceptable time that can elapse without network traffic or any other event happening on methods that are not immediate (for instance, when establishing the master SSH connection or inside methods \&\f(CW\*(C`capture\*(C'\fR, \f(CW\*(C`system\*(C'\fR, \f(CW\*(C`scp_get\*(C'\fR, etc.). .Sp See also "Timeouts". .IP "kill_ssh_on_timeout => 1" 4 .IX Item "kill_ssh_on_timeout => 1" This option tells Net::OpenSSH to kill the local slave SSH process when some operation times out. .Sp See also "Timeouts". .IP "strict_mode => 0" 4 .IX Item "strict_mode => 0" By default, the connection will be aborted if the path to the socket used for multiplexing is found to be non-secure (for instance, when any of the parent directories is writable by other users). .Sp This option can be used to disable that feature. Use with care!!! .IP "async => 1" 4 .IX Item "async => 1" By default, the constructor waits until the multiplexing socket is available. That option can be used to defer the waiting until the socket is actually used. .Sp For instance, the following code connects to several remote machines in parallel: .Sp .Vb 9 \& my (%ssh, %ls); \& # multiple connections are established in parallel: \& for my $host (@hosts) { \& $ssh{$host} = Net::OpenSSH\->new($host, async => 1); \& } \& # then to run some command in all the hosts (sequentially): \& for my $host (@hosts) { \& $ssh{$host}\->system(\*(Aqls /\*(Aq); \& } .Ve .IP "connect => 0" 4 .IX Item "connect => 0" Do not launch the master SSH process yet. .IP "master_opts => [...]" 4 .IX Item "master_opts => [...]" Additional options to pass to the \f(CW\*(C`ssh\*(C'\fR command when establishing the master connection. For instance: .Sp .Vb 2 \& my $ssh = Net::OpenSSH\->new($host, \& master_opts => [\-o => "ProxyCommand corkscrew httpproxy 8080 $host"]); .Ve .IP "default_ssh_opts => [...]" 4 .IX Item "default_ssh_opts => [...]" Default slave SSH command line options for "open_ex" and derived methods. .Sp For instance: .Sp .Vb 2 \& my $ssh = Net::OpenSSH\->new($host, \& default_ssh_opts => [\-o => "ConnectionAttempts=0"]); .Ve .IP "forward_agent => 1" 4 .IX Item "forward_agent => 1" .PD 0 .IP "forward_agent => 'always'" 4 .IX Item "forward_agent => 'always'" .PD Enables forwarding of the authentication agent. .Sp When \f(CW\*(C`always\*(C'\fR is passed as the argument, agent forwarding will be enabled by default in all the channels created from the object. Otherwise, it will have to be explicitly requested when calling the channel creating methods (i.e. \f(CW\*(C`open_ex\*(C'\fR and its derivations). .Sp This option can not be used when passing a passphrase (via "passphrase") to unlock the login private key. .Sp Note that Net::OpenSSH will not run \f(CW\*(C`ssh\-agent\*(C'\fR for you. This has to be done ahead of time and the environment variable \f(CW\*(C`SSH_AUTH_SOCK\*(C'\fR set pointing to the proper place. .IP "forward_X11 => 1" 4 .IX Item "forward_X11 => 1" Enables forwarding of the X11 protocol .ie n .IP "default_stdin_fh => $fh" 4 .el .IP "default_stdin_fh => \f(CW$fh\fR" 4 .IX Item "default_stdin_fh => $fh" .PD 0 .ie n .IP "default_stdout_fh => $fh" 4 .el .IP "default_stdout_fh => \f(CW$fh\fR" 4 .IX Item "default_stdout_fh => $fh" .ie n .IP "default_stderr_fh => $fh" 4 .el .IP "default_stderr_fh => \f(CW$fh\fR" 4 .IX Item "default_stderr_fh => $fh" .PD Default I/O streams for "open_ex" and derived methods (currently, that means any method but "pipe_in" and "pipe_out" and I plan to remove those exceptions soon!). .Sp For instance: .Sp .Vb 2 \& open my $stderr_fh, \*(Aq>>\*(Aq, \*(Aq/tmp/$host.err\*(Aq or die ...; \& open my $stdout_fh, \*(Aq>>\*(Aq, \*(Aq/tmp/$host.log\*(Aq or die ...; \& \& my $ssh = Net::OpenSSH\->new($host, default_stderr_fh => $stderr_fh, \& default_stdout_fh => $stdout_fh); \& $ssh\->error and die "SSH connection failed: " . $ssh\->error; \& \& $ssh\->scp_put("/foo/bar*", "/tmp") \& or die "scp failed: " . $ssh\->error; .Ve .ie n .IP "default_stdin_file = $fn" 4 .el .IP "default_stdin_file = \f(CW$fn\fR" 4 .IX Item "default_stdin_file = $fn" .PD 0 .ie n .IP "default_stdout_file = $fn" 4 .el .IP "default_stdout_file = \f(CW$fn\fR" 4 .IX Item "default_stdout_file = $fn" .ie n .IP "default_stderr_file = $fn" 4 .el .IP "default_stderr_file = \f(CW$fn\fR" 4 .IX Item "default_stderr_file = $fn" .PD Opens the given file names and use them as the defaults. .ie n .IP "master_stdout_fh => $fh" 4 .el .IP "master_stdout_fh => \f(CW$fh\fR" 4 .IX Item "master_stdout_fh => $fh" .PD 0 .ie n .IP "master_stderr_fh => $fh" 4 .el .IP "master_stderr_fh => \f(CW$fh\fR" 4 .IX Item "master_stderr_fh => $fh" .PD Redirect corresponding stdio streams of the master SSH process to given filehandles. .ie n .IP "master_stdout_discard => $bool" 4 .el .IP "master_stdout_discard => \f(CW$bool\fR" 4 .IX Item "master_stdout_discard => $bool" .PD 0 .ie n .IP "master_stderr_discard => $bool" 4 .el .IP "master_stderr_discard => \f(CW$bool\fR" 4 .IX Item "master_stderr_discard => $bool" .PD Discard corresponding stdio streams. .ie n .IP "expand_vars => $bool" 4 .el .IP "expand_vars => \f(CW$bool\fR" 4 .IX Item "expand_vars => $bool" Activates variable expansion inside command arguments and file paths. .Sp See "Variable expansion" below. .IP "vars => \e%vars" 4 .IX Item "vars => %vars" Initial set of variables. .IP "external_master => 1" 4 .IX Item "external_master => 1" Instead of launching a new OpenSSH client in master mode, the module tries to reuse an already existent one. \f(CW\*(C`ctl_path\*(C'\fR must also be passed when this option is set. See also "get_ctl_path". .Sp Example: .Sp .Vb 1 \& $ssh = Net::OpenSSH\->new(\*(Aqfoo\*(Aq, external_master => 1, ctl_path = $path); .Ve .Sp When \f(CW\*(C`external_master\*(C'\fR is set, the hostname argument becomes optional (\f(CW0.0.0.0\fR is passed to OpenSSH which does not use it at all). .ie n .IP "default_encoding => $encoding" 4 .el .IP "default_encoding => \f(CW$encoding\fR" 4 .IX Item "default_encoding => $encoding" .PD 0 .ie n .IP "default_stream_encoding => $encoding" 4 .el .IP "default_stream_encoding => \f(CW$encoding\fR" 4 .IX Item "default_stream_encoding => $encoding" .ie n .IP "default_argument_encoding => $encoding" 4 .el .IP "default_argument_encoding => \f(CW$encoding\fR" 4 .IX Item "default_argument_encoding => $encoding" .PD Set default encodings. See "Data encoding". .ie n .IP "password_prompt => $string" 4 .el .IP "password_prompt => \f(CW$string\fR" 4 .IX Item "password_prompt => $string" .PD 0 .ie n .IP "password_prompt => $re" 4 .el .IP "password_prompt => \f(CW$re\fR" 4 .IX Item "password_prompt => $re" .PD By default, when using password authentication, the module expects the remote side to send a password prompt matching \f(CW\*(C`/[?:]/\*(C'\fR. .Sp This option can be used to override that default for the rare cases when a different prompt is used. .Sp Examples: .Sp .Vb 2 \& password_prompt => \*(Aq]\*(Aq; # no need to escape \*(Aq]\*(Aq \& password_prompt => qr/[:?>]/; .Ve .IP "login_handler => \e&custom_login_handler" 4 .IX Item "login_handler => &custom_login_handler" Some remote SSH server may require a custom login/authentication interaction not natively supported by Net::OpenSSH. In that cases, you can use this option to replace the default login logic. .Sp The callback will be invoked repeatedly as \f(CW\*(C`custom_login_handler($ssh, $pty, $data)\*(C'\fR where \f(CW$ssh\fR is the current Net::OpenSSH object, \f(CW\*(C`pty\*(C'\fR a IO::Pty object attached to the slave \f(CW\*(C`ssh\*(C'\fR process tty and \&\f(CW$data\fR a reference to an scalar you can use at will. .Sp The login handler must return 1 after the login process has completed successfully or 0 in case it still needs to do something else. If some error happens, it must die. .Sp Note, that blocking operations should not be performed inside the login handler (at least if you want the \f(CW\*(C`async\*(C'\fR and \f(CW\*(C`timeout\*(C'\fR features to work). .Sp See also the sample script \f(CW\*(C`login_handler.pl\*(C'\fR in the \f(CW\*(C`examples\*(C'\fR directory. .Sp Usage of this option is incompatible with the \f(CW\*(C`password\*(C'\fR and \&\f(CW\*(C`passphrase\*(C'\fR options, you will have to handle password or passphrases from the custom handler yourself. .IP "master_setpgrp => 1" 4 .IX Item "master_setpgrp => 1" When this option is set, the master process is run as a different process group. As a consequence it will not die when the user presses Ctrl-C at the terminal. .Sp In order to allow the master SSH process to request any information from the user, the module may set it as the terminal controlling process while the connection is established (using "tcsetpgrp" in POSIX). Afterwards, the terminal controlling process is reset. .Sp This feature is highly experimental. Report any problems you may find, please. .IP "master_pty_force => 1" 4 .IX Item "master_pty_force => 1" By default, Net::OpenSSH attaches the master SSH process to a pty only when some kind of interactive authentication is requested. If this flag is set a pty will be attached always. .Sp That allows to get better diagnostics for some kind of errors (as for instance, bad host keys) and also allows to retrieve the pty log using get_master_pty_log. .RE .RS 4 .RE .ie n .IP $ssh\->error 4 .el .IP \f(CW$ssh\fR\->error 4 .IX Item "$ssh->error" Returns the error condition for the last performed operation. .Sp The returned value is a dualvar as $! (see "$!" in perlvar) that renders an informative message when used in string context or an error number in numeric context (error codes appear in Net::OpenSSH::Constants). .ie n .IP $ssh\->get_master_pty_log 4 .el .IP \f(CW$ssh\fR\->get_master_pty_log 4 .IX Item "$ssh->get_master_pty_log" In order to handle password authentication or entering the passphrase for a private key, Net::OpenSSH may run the master SSH process attached to a pty. .Sp In that case and after a constructor call returns a connection failure error, this method can be called to retrieve the output captured at the pty (the log is discarded when the connection is established successfully). .Sp Any data consumed from the pty by custom login handlers will be missing from the the returned log. .ie n .IP $ssh\->get_user 4 .el .IP \f(CW$ssh\fR\->get_user 4 .IX Item "$ssh->get_user" .PD 0 .ie n .IP $ssh\->get_host 4 .el .IP \f(CW$ssh\fR\->get_host 4 .IX Item "$ssh->get_host" .ie n .IP $ssh\->get_port 4 .el .IP \f(CW$ssh\fR\->get_port 4 .IX Item "$ssh->get_port" .PD Return the corresponding SSH login parameters. .ie n .IP $ssh\->get_ctl_path 4 .el .IP \f(CW$ssh\fR\->get_ctl_path 4 .IX Item "$ssh->get_ctl_path" Returns the path to the socket where the OpenSSH master process listens for new multiplexed connections. .IX Xref "get_ctl_path" .ie n .IP "($in, $out, $err, $pid) = $ssh\->open_ex(\e%opts, @cmd)" 4 .el .IP "($in, \f(CW$out\fR, \f(CW$err\fR, \f(CW$pid\fR) = \f(CW$ssh\fR\->open_ex(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($in, $out, $err, $pid) = $ssh->open_ex(%opts, @cmd)" \&\fINote: this is a low level method which, probably, you do not need to use!\fR .IX Xref "open_ex" .Sp That method starts the command \f(CW@cmd\fR on the remote machine creating new pipes for the IO channels as specified on the \f(CW%opts\fR hash. .Sp If \f(CW@cmd\fR is omitted, the remote user shell is run. .Sp Returns four values, the first three (\f(CW$in\fR, \f(CW$out\fR and \f(CW$err\fR) correspond to the local side of the pipes created (they can be undef) and the fourth (\f(CW$pid\fR) to the PID of the new SSH slave process. An empty list is returned on failure. .Sp Note that \f(CW\*(C`waitpid\*(C'\fR has to be used afterwards to reap the slave SSH process. .Sp Accepted options: .RS 4 .IP "stdin_pipe => 1" 4 .IX Item "stdin_pipe => 1" Creates a new pipe and connects the reading side to the stdin stream of the remote process. The writing side is returned as the first value (\f(CW$in\fR). .IP "stdin_pty => 1" 4 .IX Item "stdin_pty => 1" Similar to \f(CW\*(C`stdin_pipe\*(C'\fR, but instead of a regular pipe it uses a pseudo-tty (pty). .Sp Note that on some operating systems (e.g. HP-UX, AIX), ttys are not reliable. They can overflow when large chunks are written or when data is written faster than it is read. .ie n .IP "stdin_fh => $fh" 4 .el .IP "stdin_fh => \f(CW$fh\fR" 4 .IX Item "stdin_fh => $fh" Duplicates \f(CW$fh\fR and uses it as the stdin stream of the remote process. .ie n .IP "stdin_file => $filename" 4 .el .IP "stdin_file => \f(CW$filename\fR" 4 .IX Item "stdin_file => $filename" .PD 0 .IP "stdin_file => \e@open_args" 4 .IX Item "stdin_file => @open_args" .PD Opens the file of the given name for reading and uses it as the remote process stdin stream. .Sp If an array reference is passed its contents are used as the arguments for the underlying open call. For instance: .Sp .Vb 1 \& $ssh\->system({stdin_file => [\*(Aq\-|\*(Aq, \*(Aqgzip \-c \-d file.gz\*(Aq]}, $rcmd); .Ve .IP "stdin_discard => 1" 4 .IX Item "stdin_discard => 1" Uses /dev/null as the remote process stdin stream. .IP "stdout_pipe => 1" 4 .IX Item "stdout_pipe => 1" Creates a new pipe and connects the writing side to the stdout stream of the remote process. The reading side is returned as the second value (\f(CW$out\fR). .IP "stdout_pty => 1" 4 .IX Item "stdout_pty => 1" Connects the stdout stream of the remote process to the pseudo-pty. This option requires \f(CW\*(C`stdin_pty\*(C'\fR to be also set. .ie n .IP "stdout_fh => $fh" 4 .el .IP "stdout_fh => \f(CW$fh\fR" 4 .IX Item "stdout_fh => $fh" Duplicates \f(CW$fh\fR and uses it as the stdout stream of the remote process. .ie n .IP "stdout_file => $filename" 4 .el .IP "stdout_file => \f(CW$filename\fR" 4 .IX Item "stdout_file => $filename" .PD 0 .IP "stdout_file => \e@open_args" 4 .IX Item "stdout_file => @open_args" .PD Opens the file of the given filename and redirect stdout there. .IP "stdout_discard => 1" 4 .IX Item "stdout_discard => 1" Uses /dev/null as the remote process stdout stream. .IP "stdinout_socket => 1" 4 .IX Item "stdinout_socket => 1" Creates a new socketpair, attaches the stdin an stdout streams of the slave SSH process to one end and returns the other as the first value (\f(CW$in\fR) and undef for the second (\f(CW$out\fR). .Sp Example: .Sp .Vb 2 \& my ($socket, undef, undef, $pid) = $ssh\->open_ex({stdinout_socket => 1}, \& \*(Aq/bin/netcat $dest\*(Aq); .Ve .Sp See also "open2socket". .ie n .IP "stdinout_dpipe => $cmd" 4 .el .IP "stdinout_dpipe => \f(CW$cmd\fR" 4 .IX Item "stdinout_dpipe => $cmd" .PD 0 .IP "stdinout_dpipe => \e@cmd" 4 .IX Item "stdinout_dpipe => @cmd" .PD Runs the given command locally attaching its stdio streams to those of the remote SSH command. Conceptually it is equivalent to the \&\fBdpipe\fR\|(1) shell command. .IP "stderr_pipe => 1" 4 .IX Item "stderr_pipe => 1" Creates a new pipe and connects the writing side to the stderr stream of the remote process. The reading side is returned as the third value (\f(CW$err\fR). .Sp Example: .Sp .Vb 2 \& my $pid = $ssh\->open_ex({stdinout_dpipe => \*(Aqvncviewer \-stdio\*(Aq}, \& x11vnc => \*(Aq\-inetd\*(Aq); .Ve .ie n .IP "stderr_fh => $fh" 4 .el .IP "stderr_fh => \f(CW$fh\fR" 4 .IX Item "stderr_fh => $fh" Duplicates \f(CW$fh\fR and uses it as the stderr stream of the remote process. .ie n .IP "stderr_file => $filename" 4 .el .IP "stderr_file => \f(CW$filename\fR" 4 .IX Item "stderr_file => $filename" Opens the file of the given name and redirects stderr there. .IP "stderr_to_stdout => 1" 4 .IX Item "stderr_to_stdout => 1" Makes stderr point to stdout. .ie n .IP "tty => $bool" 4 .el .IP "tty => \f(CW$bool\fR" 4 .IX Item "tty => $bool" Tells \f(CW\*(C`ssh\*(C'\fR to allocate a pseudo-tty for the remote process. By default, a tty is allocated if remote command stdin stream is attached to a tty. .Sp When this flag is set and stdin is not attached to a tty, the ssh master and slave processes may generate spurious warnings about failed tty operations. This is caused by a bug present in older versions of OpenSSH. .IP "close_slave_pty => 0" 4 .IX Item "close_slave_pty => 0" When a pseudo pty is used for the stdin stream, the slave side is automatically closed on the parent process after forking the ssh command. .Sp This option disables that feature, so that the slave pty can be accessed on the parent process as \f(CW\*(C`$pty\->slave\*(C'\fR. It will have to be explicitly closed (see IO::Pty) .ie n .IP "quote_args => $bool" 4 .el .IP "quote_args => \f(CW$bool\fR" 4 .IX Item "quote_args => $bool" See "Shell quoting" below. .ie n .IP "remote_shell => $shell" 4 .el .IP "remote_shell => \f(CW$shell\fR" 4 .IX Item "remote_shell => $shell" Sets the remote shell. Allows one to change the argument quoting mechanism in a per-command fashion. .Sp This may be useful when interacting with a Windows machine where argument parsing may be done at the command level in custom ways. .Sp Example: .Sp .Vb 2 \& $ssh\->system({remote_shell => \*(AqMSWin\*(Aq}, echo => $line); \& $ssh\->system({remote_shell => \*(AqMSCmd,MSWin\*(Aq}, type => $file); .Ve .ie n .IP "forward_agent => $bool" 4 .el .IP "forward_agent => \f(CW$bool\fR" 4 .IX Item "forward_agent => $bool" Enables/disables forwarding of the authentication agent. .Sp This option can only be used when agent forwarding has been previously requested on the constructor. .ie n .IP "forward_X11 => $bool" 4 .el .IP "forward_X11 => \f(CW$bool\fR" 4 .IX Item "forward_X11 => $bool" Enables/disables forwarding of the X11 protocol. .Sp This option can only be used when X11 forwarding has been previously requested on the constructor. .IP "ssh_opts => \e@opts" 4 .IX Item "ssh_opts => @opts" List of extra options for the \f(CW\*(C`ssh\*(C'\fR command. .Sp This feature should be used with care, as the given options are not checked in any way by the module, and they could interfere with it. .ie n .IP "tunnel => $bool" 4 .el .IP "tunnel => \f(CW$bool\fR" 4 .IX Item "tunnel => $bool" Instead of executing a command in the remote host, this option instruct Net::OpenSSH to create a TCP tunnel. The arguments become the target IP and port or the remote path for an Unix socket. .Sp Example: .Sp .Vb 2 \& my ($in, $out, undef, $pid) = $ssh\->open_ex({tunnel => 1}, $IP, $port); \& my ($in, $out, undef, $pid) = $ssh\->open_ex({tunnel => 1}, $socket_path); .Ve .Sp See also "Tunnels". .ie n .IP "subsystem => $bool" 4 .el .IP "subsystem => \f(CW$bool\fR" 4 .IX Item "subsystem => $bool" Request a connection to a SSH subsystem. The name of the subsystem must be passed as an argument, as in the following example: .Sp .Vb 1 \& my $s = $ssh\->open2socket({subsystem => 1}, \*(Aqnetconf\*(Aq); .Ve .ie n .IP "encoding => $encoding" 4 .el .IP "encoding => \f(CW$encoding\fR" 4 .IX Item "encoding => $encoding" .PD 0 .ie n .IP "argument_encoding => $encoding" 4 .el .IP "argument_encoding => \f(CW$encoding\fR" 4 .IX Item "argument_encoding => $encoding" .PD Set encodings. See "Data encoding". .RE .RS 4 .Sp Usage example: .Sp .Vb 9 \& # similar to IPC::Open2 open2 function: \& my ($in_pipe, $out_pipe, undef, $pid) = \& $ssh\->open_ex( { stdin_pipe => 1, \& stdout_pipe => 1 }, \& @cmd ) \& or die "open_ex failed: " . $ssh\->error; \& # do some IO through $in/$out \& # ... \& waitpid($pid); .Ve .RE .IP "setpgrp => 1" 4 .IX Item "setpgrp => 1" Calls \f(CW\*(C`setpgrp\*(C'\fR after forking the child process. As a result it will not die when the user presses Ctrl+C at the console. See also "setpgrp" in perlfunc. .Sp Using this option without also setting \f(CW\*(C`master_setpgrp\*(C'\fR on the constructor call is mostly useless as the signal will be delivered to the master process and all the remote commands aborted. .Sp This feature is experimental. .ie n .IP "$ssh\->system(\e%opts, @cmd)" 4 .el .IP "\f(CW$ssh\fR\->system(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "$ssh->system(%opts, @cmd)" Runs the command \f(CW@cmd\fR on the remote machine. .Sp Returns true on success, undef otherwise. .Sp The error status is set to \f(CW\*(C`OSSH_SLAVE_CMD_FAILED\*(C'\fR when the remote command exits with a non zero code (the code is available from \f(CW$?\fR, see "$?" in perlvar). .Sp Example: .Sp .Vb 2 \& $ssh\->system(\*(Aqls \-R /\*(Aq) \& or die "ls failed: " . $ssh\->error"; .Ve .Sp As for \f(CW\*(C`system\*(C'\fR builtin, \f(CW\*(C`SIGINT\*(C'\fR and \f(CW\*(C`SIGQUIT\*(C'\fR signals are blocked. (see "system" in perlfunc). Also, setting \f(CW$SIG{CHLD}\fR to \&\f(CW\*(C`IGNORE\*(C'\fR or to a custom signal handler will interfere with this method. .Sp Accepted options: .RS 4 .ie n .IP "stdin_data => $input" 4 .el .IP "stdin_data => \f(CW$input\fR" 4 .IX Item "stdin_data => $input" .PD 0 .IP "stdin_data => \e@input" 4 .IX Item "stdin_data => @input" .PD Sends the given data through the stdin stream to the remote process. .Sp For example, the following code creates a file on the remote side: .Sp .Vb 2 \& $ssh\->system({stdin_data => \e@data}, "cat >/tmp/foo") \& or die "unable to write file: " . $ssh\->error; .Ve .ie n .IP "timeout => $timeout" 4 .el .IP "timeout => \f(CW$timeout\fR" 4 .IX Item "timeout => $timeout" The operation is aborted after \f(CW$timeout\fR seconds elapsed without network activity. .Sp See also "Timeouts". .IP "async => 1" 4 .IX Item "async => 1" Does not wait for the child process to exit. The PID of the new process is returned. .Sp Note that when this option is combined with \f(CW\*(C`stdin_data\*(C'\fR, the given data will be transferred to the remote side before returning control to the caller. .Sp See also the "spawn" method documentation below. .ie n .IP "stdin_fh => $fh" 4 .el .IP "stdin_fh => \f(CW$fh\fR" 4 .IX Item "stdin_fh => $fh" .PD 0 .ie n .IP "stdin_discard => $bool" 4 .el .IP "stdin_discard => \f(CW$bool\fR" 4 .IX Item "stdin_discard => $bool" .ie n .IP "stdout_fh => $fh" 4 .el .IP "stdout_fh => \f(CW$fh\fR" 4 .IX Item "stdout_fh => $fh" .ie n .IP "stdout_discard => $bool" 4 .el .IP "stdout_discard => \f(CW$bool\fR" 4 .IX Item "stdout_discard => $bool" .ie n .IP "stderr_fh => $fh" 4 .el .IP "stderr_fh => \f(CW$fh\fR" 4 .IX Item "stderr_fh => $fh" .ie n .IP "stderr_discard => $bool" 4 .el .IP "stderr_discard => \f(CW$bool\fR" 4 .IX Item "stderr_discard => $bool" .ie n .IP "stderr_to_stdout => $bool" 4 .el .IP "stderr_to_stdout => \f(CW$bool\fR" 4 .IX Item "stderr_to_stdout => $bool" .ie n .IP "stdinout_dpipe => $cmd" 4 .el .IP "stdinout_dpipe => \f(CW$cmd\fR" 4 .IX Item "stdinout_dpipe => $cmd" .ie n .IP "tty => $bool" 4 .el .IP "tty => \f(CW$bool\fR" 4 .IX Item "tty => $bool" .PD See the "open_ex" method documentation for an explanation of these options. .ie n .IP "stdin_keep_open => $bool" 4 .el .IP "stdin_keep_open => \f(CW$bool\fR" 4 .IX Item "stdin_keep_open => $bool" When \f(CW\*(C`stdin_data\*(C'\fR is given, the module closes the stdin stream once all the data has been sent. Unfortunately, some SSH buggy servers fail to handle this event correctly and close the channel prematurely. .Sp As a workaround, when this flag is set the stdin is left open until the remote process terminates. .RE .RS 4 .RE .ie n .IP "$ok = $ssh\->test(\e%opts, @cmd);" 4 .el .IP "\f(CW$ok\fR = \f(CW$ssh\fR\->test(\e%opts, \f(CW@cmd\fR);" 4 .IX Item "$ok = $ssh->test(%opts, @cmd);" Runs the given command and returns its success/failure exit status as 1 or 0 respectively. Returns undef when something goes wrong in the SSH layer. .Sp Error status is not set to OSSH_SLAVE_CMD_FAILED when the remote command exits with a non-zero code. .Sp By default this method discards the remote command \f(CW\*(C`stdout\*(C'\fR and \&\f(CW\*(C`sterr\*(C'\fR streams. .Sp Usage example: .Sp .Vb 5 \& if ($ssh\->test(ps => \-C => $executable)) { \& say "$executable is running on remote machine" \& } \& else { \& die "something got wrong: ". $ssh\->error if $ssh\->error; \& \& say "$executable is not running on remote machine" \& } .Ve .Sp This method support the same set of options as \f(CW\*(C`system\*(C'\fR, except \&\f(CW\*(C`async\*(C'\fR and \f(CW\*(C`tunnel\*(C'\fR. .ie n .IP "$output = $ssh\->capture(\e%opts, @cmd);" 4 .el .IP "\f(CW$output\fR = \f(CW$ssh\fR\->capture(\e%opts, \f(CW@cmd\fR);" 4 .IX Item "$output = $ssh->capture(%opts, @cmd);" .PD 0 .ie n .IP "@output = $ssh\->capture(\e%opts, @cmd);" 4 .el .IP "\f(CW@output\fR = \f(CW$ssh\fR\->capture(\e%opts, \f(CW@cmd\fR);" 4 .IX Item "@output = $ssh->capture(%opts, @cmd);" .PD This method is conceptually equivalent to the perl backquote operator (e.g. \f(CW\`ls\`\fR): it runs the command on the remote machine and captures its output. .Sp In scalar context returns the output as a scalar. In list context returns the output broken into lines (it honors \f(CW$/\fR, see "$/" in perlvar). .Sp The exit status of the remote command is returned in \f(CW$?\fR. .Sp When an error happens while capturing (for instance, the operation times out), the partial captured output will be returned. Error conditions have to be explicitly checked using the "error" method. For instance: .Sp .Vb 5 \& my $output = $ssh\->capture({ timeout => 10 }, \& "echo hello; sleep 20; echo bye"); \& $ssh\->error and \& warn "operation didn\*(Aqt complete successfully: ". $ssh\->error; \& print $output; .Ve .Sp Setting \f(CW$SIG{CHLD}\fR to a custom signal handler or to \f(CW\*(C`IGNORE\*(C'\fR will interfere with this method. .Sp Accepted options: .RS 4 .ie n .IP "stdin_data => $input" 4 .el .IP "stdin_data => \f(CW$input\fR" 4 .IX Item "stdin_data => $input" .PD 0 .IP "stdin_data => \e@input" 4 .IX Item "stdin_data => @input" .ie n .IP "stdin_keep_open => $bool" 4 .el .IP "stdin_keep_open => \f(CW$bool\fR" 4 .IX Item "stdin_keep_open => $bool" .PD See the "system" method documentation for an explanation of these options. .ie n .IP "timeout => $timeout" 4 .el .IP "timeout => \f(CW$timeout\fR" 4 .IX Item "timeout => $timeout" See "Timeouts". .ie n .IP "stdin_fh => $fh" 4 .el .IP "stdin_fh => \f(CW$fh\fR" 4 .IX Item "stdin_fh => $fh" .PD 0 .ie n .IP "stdin_discard => $bool" 4 .el .IP "stdin_discard => \f(CW$bool\fR" 4 .IX Item "stdin_discard => $bool" .ie n .IP "stderr_fh => $fh" 4 .el .IP "stderr_fh => \f(CW$fh\fR" 4 .IX Item "stderr_fh => $fh" .ie n .IP "stderr_discard => $bool" 4 .el .IP "stderr_discard => \f(CW$bool\fR" 4 .IX Item "stderr_discard => $bool" .ie n .IP "stderr_to_stdout => $bool" 4 .el .IP "stderr_to_stdout => \f(CW$bool\fR" 4 .IX Item "stderr_to_stdout => $bool" .ie n .IP "tty => $bool" 4 .el .IP "tty => \f(CW$bool\fR" 4 .IX Item "tty => $bool" .PD See the "open_ex" method documentation for an explanation of these options. .RE .RS 4 .RE .ie n .IP "($output, $errput) = $ssh\->capture2(\e%opts, @cmd)" 4 .el .IP "($output, \f(CW$errput\fR) = \f(CW$ssh\fR\->capture2(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($output, $errput) = $ssh->capture2(%opts, @cmd)" captures the output sent to both stdout and stderr by \f(CW@cmd\fR on the remote machine. .Sp Setting \f(CW$SIG{CHLD}\fR to a custom signal handler or to \f(CW\*(C`IGNORE\*(C'\fR will also interfere with this method. .Sp The accepted options are: .RS 4 .ie n .IP "stdin_data => $input" 4 .el .IP "stdin_data => \f(CW$input\fR" 4 .IX Item "stdin_data => $input" .PD 0 .IP "stdin_data => \e@input" 4 .IX Item "stdin_data => @input" .ie n .IP "stdin_keep_open => $bool" 4 .el .IP "stdin_keep_open => \f(CW$bool\fR" 4 .IX Item "stdin_keep_open => $bool" .PD See the "system" method documentation for an explanation of these options. .ie n .IP "timeout => $timeout" 4 .el .IP "timeout => \f(CW$timeout\fR" 4 .IX Item "timeout => $timeout" See "Timeouts". .ie n .IP "stdin_fh => $fh" 4 .el .IP "stdin_fh => \f(CW$fh\fR" 4 .IX Item "stdin_fh => $fh" .PD 0 .ie n .IP "stdin_discard => $bool" 4 .el .IP "stdin_discard => \f(CW$bool\fR" 4 .IX Item "stdin_discard => $bool" .ie n .IP "tty => $bool" 4 .el .IP "tty => \f(CW$bool\fR" 4 .IX Item "tty => $bool" .PD See the "open_ex" method documentation for an explanation of these options. .RE .RS 4 .RE .ie n .IP "($in, $pid) = $ssh\->pipe_in(\e%opts, @cmd)" 4 .el .IP "($in, \f(CW$pid\fR) = \f(CW$ssh\fR\->pipe_in(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($in, $pid) = $ssh->pipe_in(%opts, @cmd)" This method is similar to the following Perl \f(CW\*(C`open\*(C'\fR call .IX Xref "pipe_in" .Sp .Vb 1 \& $pid = open $in, \*(Aq|\-\*(Aq, @cmd .Ve .Sp but running \f(CW@cmd\fR on the remote machine (see "open" in perlfunc). .Sp No options are currently accepted. .Sp There is no need to perform a waitpid on the returned PID as it will be done automatically by perl when \f(CW$in\fR is closed. .Sp Example: .Sp .Vb 4 \& my ($in, $pid) = $ssh\->pipe_in(\*(Aqcat >/tmp/fpp\*(Aq) \& or die "pipe_in failed: " . $ssh\->error; \& print $in $_ for @data; \& close $in or die "close failed"; .Ve .ie n .IP "($out, $pid) = $ssh\->pipe_out(\e%opts, @cmd)" 4 .el .IP "($out, \f(CW$pid\fR) = \f(CW$ssh\fR\->pipe_out(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($out, $pid) = $ssh->pipe_out(%opts, @cmd)" Reciprocal to previous method, it is equivalent to .IX Xref "pipe_out" .Sp .Vb 1 \& $pid = open $out, \*(Aq\-|\*(Aq, @cmd .Ve .Sp running \f(CW@cmd\fR on the remote machine. .Sp No options are currently accepted. .ie n .IP "($in, $out, $pid) = $ssh\->open2(\e%opts, @cmd)" 4 .el .IP "($in, \f(CW$out\fR, \f(CW$pid\fR) = \f(CW$ssh\fR\->open2(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($in, $out, $pid) = $ssh->open2(%opts, @cmd)" .PD 0 .ie n .IP "($pty, $pid) = $ssh\->open2pty(\e%opts, @cmd)" 4 .el .IP "($pty, \f(CW$pid\fR) = \f(CW$ssh\fR\->open2pty(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($pty, $pid) = $ssh->open2pty(%opts, @cmd)" .ie n .IP "($socket, $pid) = $ssh\->open2socket(\e%opts, @cmd)" 4 .el .IP "($socket, \f(CW$pid\fR) = \f(CW$ssh\fR\->open2socket(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($socket, $pid) = $ssh->open2socket(%opts, @cmd)" .ie n .IP "($in, $out, $err, $pid) = $ssh\->open3(\e%opts, @cmd)" 4 .el .IP "($in, \f(CW$out\fR, \f(CW$err\fR, \f(CW$pid\fR) = \f(CW$ssh\fR\->open3(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($in, $out, $err, $pid) = $ssh->open3(%opts, @cmd)" .ie n .IP "($pty, $err, $pid) = $ssh\->open3pty(\e%opts, @cmd)" 4 .el .IP "($pty, \f(CW$err\fR, \f(CW$pid\fR) = \f(CW$ssh\fR\->open3pty(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "($pty, $err, $pid) = $ssh->open3pty(%opts, @cmd)" .PD Shortcuts around "open_ex" method. .ie n .IP "$pid = $ssh\->spawn(\e%opts, @_)" 4 .el .IP "\f(CW$pid\fR = \f(CW$ssh\fR\->spawn(\e%opts, \f(CW@_\fR)" 4 .IX Item "$pid = $ssh->spawn(%opts, @_)" Another "open_ex" shortcut, it launches a new remote process in the background and returns the PID of the local slave SSH process. .IX Xref "spawn" .Sp At some later point in your script, \f(CW\*(C`waitpid\*(C'\fR should be called on the returned PID in order to reap the slave SSH process. .Sp For instance, you can run some command on several hosts in parallel with the following code: .Sp .Vb 7 \& my %conn = map { $_ => Net::OpenSSH\->new($_, async => 1) } @hosts; \& my @pid; \& for my $host (@hosts) { \& open my($fh), \*(Aq>\*(Aq, "/tmp/out\-$host.txt" \& or die "unable to create file: $!"; \& push @pid, $conn{$host}\->spawn({stdout_fh => $fh}, $cmd); \& } \& \& waitpid($_, 0) for @pid; .Ve .Sp Note that \f(CW\*(C`spawn\*(C'\fR should not be used to start detached remote processes that may survive the local program (see also the "FAQ" about running remote processes detached). .ie n .IP "($socket, $pid) = $ssh\->open_tunnel(\e%opts, $dest_host, $port)" 4 .el .IP "($socket, \f(CW$pid\fR) = \f(CW$ssh\fR\->open_tunnel(\e%opts, \f(CW$dest_host\fR, \f(CW$port\fR)" 4 .IX Item "($socket, $pid) = $ssh->open_tunnel(%opts, $dest_host, $port)" .PD 0 .ie n .IP "($socket, $pid) = $ssh\->open_tunnel(\e%opts, $socket_path)" 4 .el .IP "($socket, \f(CW$pid\fR) = \f(CW$ssh\fR\->open_tunnel(\e%opts, \f(CW$socket_path\fR)" 4 .IX Item "($socket, $pid) = $ssh->open_tunnel(%opts, $socket_path)" .PD Similar to "open2socket", but instead of running a command, it opens a TCP tunnel to the given address. See also "Tunnels". .IX Xref "open_tunnel" .ie n .IP "$out = $ssh\->capture_tunnel(\e%opts, $dest_host, $port)" 4 .el .IP "\f(CW$out\fR = \f(CW$ssh\fR\->capture_tunnel(\e%opts, \f(CW$dest_host\fR, \f(CW$port\fR)" 4 .IX Item "$out = $ssh->capture_tunnel(%opts, $dest_host, $port)" .PD 0 .ie n .IP "@out = $ssh\->capture_tunnel(\e%opts, $dest_host, $port)" 4 .el .IP "\f(CW@out\fR = \f(CW$ssh\fR\->capture_tunnel(\e%opts, \f(CW$dest_host\fR, \f(CW$port\fR)" 4 .IX Item "@out = $ssh->capture_tunnel(%opts, $dest_host, $port)" .PD Similar to "capture", but instead of running a command, it opens a TCP tunnel. .IX Xref "capture_tunnel" .Sp Example: .Sp .Vb 5 \& $out = $ssh\->capture_tunnel({stdin_data => join("\er\en", \& "GET / HTTP/1.0", \& "Host: www.perl.org", \& "", "") }, \& \*(Aqwww.perl.org\*(Aq, 80) .Ve .Sp See also "Tunnels". .ie n .IP "$ssh\->scp_get(\e%opts, $remote1, $remote2,..., $local_dir_or_file)" 4 .el .IP "\f(CW$ssh\fR\->scp_get(\e%opts, \f(CW$remote1\fR, \f(CW$remote2\fR,..., \f(CW$local_dir_or_file\fR)" 4 .IX Item "$ssh->scp_get(%opts, $remote1, $remote2,..., $local_dir_or_file)" .PD 0 .ie n .IP "$ssh\->scp_put(\e%opts, $local, $local2,..., $remote_dir_or_file)" 4 .el .IP "\f(CW$ssh\fR\->scp_put(\e%opts, \f(CW$local\fR, \f(CW$local2\fR,..., \f(CW$remote_dir_or_file\fR)" 4 .IX Item "$ssh->scp_put(%opts, $local, $local2,..., $remote_dir_or_file)" .PD These two methods are wrappers around the \f(CW\*(C`scp\*(C'\fR command that allow transfers of files to/from the remote host using the existing SSH master connection. .Sp When transferring several files, the target argument must point to an existing directory. If only one file is to be transferred, the target argument can be a directory or a file name or can be omitted. For instance: .Sp .Vb 2 \& $ssh\->scp_get({glob => 1}, \*(Aq/var/tmp/foo*\*(Aq, \*(Aq/var/tmp/bar*\*(Aq, \*(Aq/tmp\*(Aq); \& $ssh\->scp_put(\*(Aq/etc/passwd\*(Aq); .Ve .Sp Both "scp_get" and "scp_put" methods return a true value when all the files are transferred correctly, otherwise they return undef. .Sp Accepted options: .RS 4 .IP "quiet => 0" 4 .IX Item "quiet => 0" By default, \f(CW\*(C`scp\*(C'\fR is called with the quiet flag \f(CW\*(C`\-q\*(C'\fR enabled in order to suppress progress information. This option allows one to re-enable the progress indication bar. .IP "verbose => 1" 4 .IX Item "verbose => 1" Calls \f(CW\*(C`scp\*(C'\fR with the \f(CW\*(C`\-v\*(C'\fR flag. .IP "recursive => 1" 4 .IX Item "recursive => 1" Copies files and directories recursively. .IP "glob => 1" 4 .IX Item "glob => 1" Enables expansion of shell metacharacters in the sources list so that wildcards can be used to select files. .ie n .IP "glob_flags => $flags" 4 .el .IP "glob_flags => \f(CW$flags\fR" 4 .IX Item "glob_flags => $flags" Second argument passed to File::Glob::bsd_glob function. Only available for "scp_put" method. .IP "copy_attrs => 1" 4 .IX Item "copy_attrs => 1" Copies modification and access times and modes from the original files. .ie n .IP "bwlimit => $Kbits" 4 .el .IP "bwlimit => \f(CW$Kbits\fR" 4 .IX Item "bwlimit => $Kbits" Limits the used bandwidth, specified in Kbit/s. .ie n .IP "timeout => $secs" 4 .el .IP "timeout => \f(CW$secs\fR" 4 .IX Item "timeout => $secs" The transfer is aborted if the connection does not finish before the given timeout elapses. See also "Timeouts". .IP "async => 1" 4 .IX Item "async => 1" Does not wait for the \f(CW\*(C`scp\*(C'\fR command to finish. When this option is used, the method returns the PID of the child \f(CW\*(C`scp\*(C'\fR process. .Sp For instance, it is possible to transfer files to several hosts in parallel as follows: .Sp .Vb 10 \& use Errno; \& my (%pid, %ssh); \& for my $host (@hosts) { \& $ssh{$host} = Net::OpenSSH\->new($host, async => 1); \& } \& for my $host (@hosts) { \& $pid{$host} = $ssh{$host}\->scp_put({async => 1}, $local_fn, $remote_fn) \& or warn "scp_put to $host failed: " . $ssh{$host}\->error . "\en"; \& } \& for my $host (@hosts) { \& if (my $pid = $pid{$host}) { \& if (waitpid($pid, 0) > 0) { \& my $exit = ($? >> 8); \& $exit and warn "transfer of file to $host failed ($exit)\en"; \& } \& else { \& redo if ($! == EINTR); \& warn "waitpid($pid) failed: $!\en"; \& } \& } \& } .Ve .ie n .IP "stdout_fh => $fh" 4 .el .IP "stdout_fh => \f(CW$fh\fR" 4 .IX Item "stdout_fh => $fh" .PD 0 .ie n .IP "stderr_fh => $fh" 4 .el .IP "stderr_fh => \f(CW$fh\fR" 4 .IX Item "stderr_fh => $fh" .IP "stderr_to_stdout => 1" 4 .IX Item "stderr_to_stdout => 1" .PD These options are passed unchanged to method "open_ex", allowing capture of the output of the \f(CW\*(C`scp\*(C'\fR program. .Sp Note that \f(CW\*(C`scp\*(C'\fR will not generate progress reports unless its stdout stream is attached to a tty. .IP "ssh_opts => \e@opts" 4 .IX Item "ssh_opts => @opts" List of extra options for the \f(CW\*(C`ssh\*(C'\fR command. .Sp This feature should be used with care, as the given options are not checked in any way by the module, and they could interfere with it. .RE .RS 4 .RE .ie n .IP "$ssh\->rsync_get(\e%opts, $remote1, $remote2,..., $local_dir_or_file)" 4 .el .IP "\f(CW$ssh\fR\->rsync_get(\e%opts, \f(CW$remote1\fR, \f(CW$remote2\fR,..., \f(CW$local_dir_or_file\fR)" 4 .IX Item "$ssh->rsync_get(%opts, $remote1, $remote2,..., $local_dir_or_file)" .PD 0 .ie n .IP "$ssh\->rsync_put(\e%opts, $local1, $local2,..., $remote_dir_or_file)" 4 .el .IP "\f(CW$ssh\fR\->rsync_put(\e%opts, \f(CW$local1\fR, \f(CW$local2\fR,..., \f(CW$remote_dir_or_file\fR)" 4 .IX Item "$ssh->rsync_put(%opts, $local1, $local2,..., $remote_dir_or_file)" .PD These methods use \f(CW\*(C`rsync\*(C'\fR over SSH to transfer files from/to the remote machine. .Sp They accept the same set of options as the \f(CW\*(C`scp\*(C'\fR ones. .Sp Any unrecognized option will be passed as an argument to the \f(CW\*(C`rsync\*(C'\fR command (see \fBrsync\fR\|(1)). Underscores can be used instead of dashes in \f(CW\*(C`rsync\*(C'\fR option names. .Sp For instance: .Sp .Vb 4 \& $ssh\->rsync_get({exclude => \*(Aq*~\*(Aq, \& verbose => 1, \& safe_links => 1}, \& \*(Aq/remote/dir\*(Aq, \*(Aq/local/dir\*(Aq); .Ve .ie n .IP "$sftp = $ssh\->sftp(%sftp_opts)" 4 .el .IP "\f(CW$sftp\fR = \f(CW$ssh\fR\->sftp(%sftp_opts)" 4 .IX Item "$sftp = $ssh->sftp(%sftp_opts)" Creates a new Net::SFTP::Foreign object for SFTP interaction that runs through the ssh master connection. .IX Xref "Net_SFTP_Foreign" .ie n .IP "@call = $ssh\->make_remote_command(\e%opts, @cmd)" 4 .el .IP "\f(CW@call\fR = \f(CW$ssh\fR\->make_remote_command(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "@call = $ssh->make_remote_command(%opts, @cmd)" .PD 0 .ie n .IP "$call = $ssh\->make_remote_command(\e%opts, @cmd)" 4 .el .IP "\f(CW$call\fR = \f(CW$ssh\fR\->make_remote_command(\e%opts, \f(CW@cmd\fR)" 4 .IX Item "$call = $ssh->make_remote_command(%opts, @cmd)" .PD This method returns the arguments required to execute a command on the remote machine via SSH. For instance: .Sp .Vb 2 \& my @call = $ssh\->make_remote_command(ls => "/var/log"); \& system @call; .Ve .Sp In scalar context, returns the arguments quoted and joined into one string: .Sp .Vb 2 \& my $remote = $ssh\->make_remote_comand("cd /tmp/ && tar xf \-"); \& system "tar cf \- . | $remote"; .Ve .Sp The options accepted are as follows: .RS 4 .ie n .IP "tty => $bool" 4 .el .IP "tty => \f(CW$bool\fR" 4 .IX Item "tty => $bool" Enables/disables allocation of a tty on the remote side. .ie n .IP "forward_agent => $bool" 4 .el .IP "forward_agent => \f(CW$bool\fR" 4 .IX Item "forward_agent => $bool" Enables/disables forwarding of authentication agent. .Sp This option can only be used when agent forwarding has been previously requested on the constructor. .IP "tunnel => 1" 4 .IX Item "tunnel => 1" Return a command to create a connection to some TCP server reachable from the remote host. In that case the arguments are the destination address and port. For instance: .Sp .Vb 1 \& $cmd = $ssh\->make_remote_command({tunnel => 1}, $host, $port); .Ve .IP "subsystem => 1" 4 .IX Item "subsystem => 1" Return a command for invoking a SSH subsystem (i.e. SFTP or netconf). In that case the only argument is the subsystem name. .RE .RS 4 .RE .ie n .IP $ssh\->wait_for_master($async) 4 .el .IP \f(CW$ssh\fR\->wait_for_master($async) 4 .IX Item "$ssh->wait_for_master($async)" When the connection has been established by calling the constructor with the \f(CW\*(C`async\*(C'\fR option, this call allows one to advance the process. .Sp If \f(CW$async\fR is true, it will perform any work that can be done immediately without waiting (for instance, entering the password or checking for the existence of the multiplexing socket) and then return. If a false value is given, it will finalize the connection process and wait until the multiplexing socket is available. .Sp It returns a true value after the connection has been successfully established. False is returned if the connection process fails or if it has not yet completed (then, the "error" method can be used to distinguish between both cases). .Sp From version 0.64 upwards, undef is returned when the master is still in an unstable state (login, killing, etc.) and 0 when it is in a stable state (running, stopped or gone). .ie n .IP $ssh\->check_master 4 .el .IP \f(CW$ssh\fR\->check_master 4 .IX Item "$ssh->check_master" This method runs several checks to ensure that the master connection is still alive. .ie n .IP $ssh\->shell_quote(@args) 4 .el .IP \f(CW$ssh\fR\->shell_quote(@args) 4 .IX Item "$ssh->shell_quote(@args)" Returns the list of arguments quoted so that they will be restored to their original form when parsed by the remote shell. .Sp In scalar context returns the list of arguments quoted and joined. .Sp Usually this task is done automatically by the module. See "Shell quoting" below. .Sp This method can also be used as a class method. .Sp Example: .Sp .Vb 2 \& my $quoted_args = Net::OpenSSH\->shell_quote(@args); \& system(\*(Aqssh\*(Aq, \*(Aq\-\-\*(Aq, $host, $quoted_args); .Ve .ie n .IP $ssh\->shell_quote_glob(@args) 4 .el .IP \f(CW$ssh\fR\->shell_quote_glob(@args) 4 .IX Item "$ssh->shell_quote_glob(@args)" This method is like the previous \f(CW\*(C`shell_quote\*(C'\fR but leaves wildcard characters unquoted. .Sp It can be used as a class method also. .ie n .IP $ssh\->set_expand_vars($bool) 4 .el .IP \f(CW$ssh\fR\->set_expand_vars($bool) 4 .IX Item "$ssh->set_expand_vars($bool)" Enables/disables variable expansion feature (see "Variable expansion"). .ie n .IP $ssh\->get_expand_vars 4 .el .IP \f(CW$ssh\fR\->get_expand_vars 4 .IX Item "$ssh->get_expand_vars" Returns current state of variable expansion feature. .ie n .IP "$ssh\->set_var($name, $value)" 4 .el .IP "\f(CW$ssh\fR\->set_var($name, \f(CW$value\fR)" 4 .IX Item "$ssh->set_var($name, $value)" .PD 0 .ie n .IP "$ssh\->get_var($name, $value)" 4 .el .IP "\f(CW$ssh\fR\->get_var($name, \f(CW$value\fR)" 4 .IX Item "$ssh->get_var($name, $value)" .PD These methods allow one to change and to retrieve the value of the given name. .ie n .IP $ssh\->get_master_pid 4 .el .IP \f(CW$ssh\fR\->get_master_pid 4 .IX Item "$ssh->get_master_pid" Returns the PID of the master SSH process .ie n .IP $ssh\->master_exited 4 .el .IP \f(CW$ssh\fR\->master_exited 4 .IX Item "$ssh->master_exited" This methods allows one to tell the module that the master process has exited when we get its PID from some external wait or waitpid call. For instance: .Sp .Vb 1 \& my $ssh = Net::OpenSSH\->new(\*(Aqfoo\*(Aq, async => 1); \& \& # create new processes \& # ... \& \& # rip them... \& my $master_pid = $ssh\->master_pid; \& while ((my $pid = wait) > 0) { \& if ($pid == $master_pid) { \& $ssh\->master_exited; \& } \& } .Ve .Sp If your program rips the master process and this method is not called, the OS could reassign the PID to a new unrelated process and the module would try to kill it at object destruction time. .ie n .IP $ssh\->disconnect($async) 4 .el .IP \f(CW$ssh\fR\->disconnect($async) 4 .IX Item "$ssh->disconnect($async)" Shuts down the SSH connection. .Sp Usually, you don't need to call this method explicitly, but just let the Net::OpenSSH object go out of scope. .Sp If \f(CW\*(C`async\*(C'\fR is true, it doesn't wait for the SSH connection to terminate. In that case, "wait_for_master" must be called repeatedly until the shutdown sequence terminates (See the "AnyEvent" integration section below). .ie n .IP $ssh\->restart($async) 4 .el .IP \f(CW$ssh\fR\->restart($async) 4 .IX Item "$ssh->restart($async)" Restarts the SSH session closing any open connection and creating a new one. Any open channel would also be killed. .Sp Note that calling this method may request again the password or passphrase from the user. .Sp In asynchronous mode, this method requires the connection to be terminated before it gets called. Afterwards, \f(CW\*(C`wait_for_master\*(C'\fR should be called repeatedly until the new connection is established. For instance: .Sp .Vb 10 \& my $async = 1; \& $ssh\->disconnect($async); \& while (1) { \& defined $ssh\->wait_for_master($async) # returns 0 when the \& # disconnect process \& # finishes \& and last; \& do_something_else(); \& } \& $ssh\->restart($async); \& while (1) { \& defined $ssh\->wait_for_master($async) \& and last; \& do_something_else(); \& } .Ve .ie n .IP "$pid = $ssh\->sshfs_import(\e%opts, $remote_fs, $local_mnt_point)" 4 .el .IP "\f(CW$pid\fR = \f(CW$ssh\fR\->sshfs_import(\e%opts, \f(CW$remote_fs\fR, \f(CW$local_mnt_point\fR)" 4 .IX Item "$pid = $ssh->sshfs_import(%opts, $remote_fs, $local_mnt_point)" .PD 0 .ie n .IP "$pid = $ssh\->sshfs_export(\e%opts, $local_fs, $remote_mnt_point)" 4 .el .IP "\f(CW$pid\fR = \f(CW$ssh\fR\->sshfs_export(\e%opts, \f(CW$local_fs\fR, \f(CW$remote_mnt_point\fR)" 4 .IX Item "$pid = $ssh->sshfs_export(%opts, $local_fs, $remote_mnt_point)" .PD These methods use \fBsshfs\fR\|(1) to import or export a file system through the SSH connection. .Sp They return the \f(CW$pid\fR of the \f(CW\*(C`sshfs\*(C'\fR process or of the slave \f(CW\*(C`ssh\*(C'\fR process used to proxy it. Killing that process unmounts the file system, though, it may be probably better to use \fBfusermount\fR\|(1). .Sp The options accepted are as follows: .RS 4 .IP "ssh_opts => \e@ssh_opts" 4 .IX Item "ssh_opts => @ssh_opts" Options passed to the slave \f(CW\*(C`ssh\*(C'\fR process. .IP "sshfs_opts => \e@sshfs_opts" 4 .IX Item "sshfs_opts => @sshfs_opts" Options passed to the \f(CW\*(C`sshfs\*(C'\fR command. For instance, to mount the file system in read-only mode: .Sp .Vb 2 \& my $pid = $ssh\->sshfs_export({sshfs_opts => [\-o => \*(Aqro\*(Aq]}, \& "/", "/mnt/foo"); .Ve .RE .RS 4 .Sp Note that this command requires a recent version of \f(CW\*(C`sshfs\*(C'\fR to work (at the time of writing, it requires the yet unreleased version available from the FUSE git repository!). .Sp See also the \fBsshfs\fR\|(1) man page and the \f(CW\*(C`sshfs\*(C'\fR and FUSE web sites at and respectively. .RE .ie n .IP "$or = $ssh\->object_remote(@args)" 4 .el .IP "\f(CW$or\fR = \f(CW$ssh\fR\->object_remote(@args)" 4 .IX Item "$or = $ssh->object_remote(@args)" Returns an Object::Remote::Connection instance running on top of the Net::OpenSSH connection. .IX Xref "Object_Remote" .Sp Example: .Sp .Vb 3 \& my $or = $ssh\->object_remote; \& my $hostname = Sys::Hostname\->can::on($or, \*(Aqhostname\*(Aq); \& say $hostname\->(); .Ve .Sp See also Object::Remote. .ie n .IP "$any = $ssh\->any(%opts)" 4 .el .IP "\f(CW$any\fR = \f(CW$ssh\fR\->any(%opts)" 4 .IX Item "$any = $ssh->any(%opts)" Wraps the current object inside a Net::SSH::Any one. .IX Xref "Net_SSH_Any" .Sp Example: .Sp .Vb 2 \& my $any = $ssh\->any; \& my $content = $any\->scp_get_content("my\-file.txt"); .Ve .ie n .IP "$pid = $ssh\->disown_master" 4 .el .IP "\f(CW$pid\fR = \f(CW$ssh\fR\->disown_master" 4 .IX Item "$pid = $ssh->disown_master" Under normal operation Net::OpenSSH controls the life-time of the master \f(CW\*(C`ssh\*(C'\fR process and when the object is destroyed the master process and any connection running over it are terminated. .Sp In some (rare) cases, it is desirable to let the master process and all the running connections survive. Calling this method does just that, it tells Net::OpenSSH object that the master process is not its own anymore. .Sp The return value is the PID of the master process. .Sp Note also that disowning the master process does not affect the operation of the module in any other regard. .Sp For instance: .Sp .Vb 6 \& # See examples/sshfs_mount.pl for a working program \& my $ssh = Net::OpenSSH\->new($host); \& my $sshfs_pid = $ssh\->sshfs_import("/home/foo", "my\-remote\-home"); \& $ssh\->disown_master; \& $ssh\->stop; # tells the master to stop accepting requests \& exit(0); .Ve .ie n .IP $ssh\->default_ssh_configuration 4 .el .IP \f(CW$ssh\fR\->default_ssh_configuration 4 .IX Item "$ssh->default_ssh_configuration" Allows one to retrieve the default SSH configuration for the target host from system files (i.e. \f(CW\*(C`/etc/ssh/ssh_config\*(C'\fR) and user files (\f(CW\*(C`~/.ssh/config\*(C'\fR). .Sp Under the hood, this method just calls \f(CW\*(C`ssh \-G $host\*(C'\fR and returns the output unprocessed. .Sp Example: .Sp .Vb 5 \& my $ssh = Net::OpenSSH\->new($host, connect => 0); \& my $txt = $ssh\->default_ssh_configuration; \& my @lines = split /^/m, $txt; \& chomp @lines; \& my %def_cfg = map split(/\es+/, $_, 2), @lines; .Ve .SS "Shell quoting" .IX Subsection "Shell quoting" By default, when invoking remote commands, this module tries to mimic perl \f(CW\*(C`system\*(C'\fR builtin in regard to argument processing. Quoting "system" in perlfunc: .PP .Vb 8 \& Argument processing varies depending on the number of arguments. If \& there is more than one argument in LIST, or if LIST is an array with \& more than one value, starts the program given by the first element \& of the list with arguments given by the rest of the list. If there \& is only one scalar argument, the argument is checked for shell \& metacharacters, and if there are any, the entire argument is passed \& to the system\*(Aqs command shell for parsing (this is "/bin/sh \-c" on \& Unix platforms, but varies on other platforms). .Ve .PP Take for example Net::OpenSSH "system" method: .PP .Vb 2 \& $ssh\->system("ls \-l *"); \& $ssh\->system(\*(Aqls\*(Aq, \*(Aq\-l\*(Aq, \*(Aq/\*(Aq); .Ve .PP The first call passes the argument unchanged to ssh and it is executed in the remote side through the shell which interprets metacharacters. .PP The second call escapes any shell metacharacters so that, effectively, it is equivalent to calling the command directly and not through the shell. .PP Under the hood, as the Secure Shell protocol does not provide for this mode of operation and always spawns a new shell where it runs the given command, Net::OpenSSH quotes any shell metacharacters in the command list. .PP All the methods that invoke a remote command (system, open_ex, etc.) accept the option \f(CW\*(C`quote_args\*(C'\fR that allows one to force/disable shell quoting. .PP For instance: .PP .Vb 1 \& $ssh\->system({quote_args => 1}, "/path with spaces/bin/foo"); .Ve .PP will correctly handle the spaces in the program path. .PP The shell quoting mechanism implements some extensions (for instance, performing redirections to /dev/null on the remote side) that can be disabled with the option \f(CW\*(C`quote_args_extended\*(C'\fR: .PP .Vb 3 \& $ssh\->system({ stderr_discard => 1, \& quote_args => 1, quote_args_extended => 0 }, \& @cmd); .Ve .PP The option \f(CW\*(C`quote_args\*(C'\fR can also be used to disable quoting when more than one argument is passed. For instance, to get some pattern expanded by the remote shell: .PP .Vb 1 \& $ssh\->system({quote_args => 0}, \*(Aqls\*(Aq, \*(Aq\-l\*(Aq, "/tmp/files_*.dat"); .Ve .PP The method \f(CW\*(C`shell_quote\*(C'\fR can be used to selectively quote some arguments and leave others untouched: .PP .Vb 3 \& $ssh\->system({quote_args => 0}, \& $ssh\->shell_quote(\*(Aqls\*(Aq, \*(Aq\-l\*(Aq), \& "/tmp/files_*.dat"); .Ve .PP When the glob option is set in \f(CW\*(C`scp\*(C'\fR and \f(CW\*(C`rsync\*(C'\fR file transfer methods, an alternative quoting method which knows about file wildcards and passes them unquoted is used. The set of wildcards recognized currently is the one supported by \fBbash\fR\|(1). .PP Another way to selectively use quote globing or fully disable quoting for some specific arguments is to pass them as scalar references or double scalar references respectively. In practice, that means prepending them with one or two backslashes. For instance: .PP .Vb 2 \& # quote the last argument for globing: \& $ssh\->system(\*(Aqls\*(Aq, \*(Aq\-l\*(Aq, \e\*(Aq/tmp/my files/filed_*dat\*(Aq); \& \& # append a redirection to the remote command \& $ssh\->system(\*(Aqls\*(Aq, \*(Aq\-lR\*(Aq, \e\e\*(Aq>/tmp/ls\-lR.txt\*(Aq); \& \& # expand remote shell variables and glob in the same command: \& $ssh\->system(\*(Aqtar\*(Aq, \*(Aqczf\*(Aq, \e\e\*(Aq$HOME/out.tgz\*(Aq, \e\*(Aq/var/log/server.*.log\*(Aq); .Ve .PP As shell quoting is a tricky matter, I expect bugs to appear in this area. You can see how \f(CW\*(C`ssh\*(C'\fR is called, and the quoting used setting the following debug flag: .PP .Vb 1 \& $Net::OpenSSH::debug |= 16; .Ve .PP By default, the module assumes the remote shell is some variant of a POSIX or Bourne shell (\f(CW\*(C`bash\*(C'\fR, \f(CW\*(C`dash\*(C'\fR, \f(CW\*(C`ksh\*(C'\fR, etc.). If this is not the case, the construction option \f(CW\*(C`remote_shell\*(C'\fR can be used to select an alternative quoting mechanism. .PP For instance: .PP .Vb 2 \& $ssh = Net::OpenSSH\->new($host, remote_shell => \*(Aqcsh\*(Aq); \& $ssh\->system(echo => "hard\en to\en quote\en argument!"); .Ve .PP Currently there are quoters available for POSIX (Bourne) compatible shells, \f(CW\*(C`csh\*(C'\fR and the two Windows variants \f(CW\*(C`MSWin\*(C'\fR (for servers using Win32::CreateProcess, see Net::OpenSSH::ShellQuoter::MSWin) and \f(CW\*(C`MSCmd\*(C'\fR (for servers using \&\f(CW\*(C`cmd.exe\*(C'\fR, see Net::OpenSSH::ShellQuoter::MSCmd). .PP In any case, you can always do the quoting yourself and pass the quoted remote command as a single string: .PP .Vb 2 \& # for VMS \& $ssh\->system(\*(AqDIR/SIZE NFOO::USERS:[JSMITH.DOCS]*.TXT;0\*(Aq); .Ve .PP Note that the current quoting mechanism does not handle possible aliases defined by the remote shell. In that case, to force execution of the command instead of the alias, the full path to the command must be used. .SS Timeouts .IX Subsection "Timeouts" In order to stop remote processes when they timeout, the ideal approach would be to send them signals through the SSH connection as specified by the protocol standard. .PP Unfortunately OpenSSH does not implement that feature so Net::OpenSSH has to use other imperfect approaches: .IP \(bu 4 close slave I/O streams .Sp Closing the STDIN and STDOUT streams of the unresponsive remote process will effectively deliver a SIGPIPE when it tries to access any of them. .Sp Remote processes may not access STDIN or STDOUT and even then, Net::OpenSSH can only close these channels when it is capturing them, so this approach does not always work. .IP \(bu 4 killing the local SSH slave process .Sp This action may leave the remote process running, creating a remote orphan so Net::OpenSSH does not use it unless the construction option \&\f(CW\*(C`kill_ssh_on_timeout\*(C'\fR is set. .PP Luckily, future versions of OpenSSH will support signaling remote processes via the mux channel. .SS "Variable expansion" .IX Subsection "Variable expansion" The variable expansion feature allows one to define variables that are expanded automatically inside command arguments and file paths. .PP This feature is disabled by default. It is intended to be used with Net::OpenSSH::Parallel and other similar modules. .PP Variables are delimited by a pair of percent signs (\f(CW\*(C`%\*(C'\fR), for instance \f(CW\*(C`%HOST%\*(C'\fR. Also, two consecutive percent signs are replaced by a single one. .PP The special variables \f(CW\*(C`HOST\*(C'\fR, \f(CW\*(C`USER\*(C'\fR and \f(CW\*(C`PORT\*(C'\fR are maintained internally by the module and take the obvious values. .PP Variable expansion is performed before shell quoting (see "Shell quoting"). .PP Some usage example: .PP .Vb 3 \& my $ssh = Net::OpenSSH\->new(\*(Aqserver.foo.com\*(Aq, expand_vars => 1); \& $ssh\->set_var(ID => 42); \& $ssh\->system("ls >/tmp/ls.out\-%HOST%\-%ID%"); .Ve .PP will redirect the output of the \f(CW\*(C`ls\*(C'\fR command to \&\f(CW\*(C`/tmp/ls.out\-server.foo.com\-42\*(C'\fR on the remote host. .SS Tunnels .IX Subsection "Tunnels" Besides running commands on the remote host, Net::OpenSSH also allows one to tunnel TCP connections to remote machines reachable from the SSH server. .PP That feature is made available through the \f(CW\*(C`tunnel\*(C'\fR option of the "open_ex" method, and also through wrapper methods "open_tunnel" and "capture_tunnel" and most others where it makes sense. .PP Example: .PP .Vb 5 \& $ssh\->system({tunnel => 1, \& stdin_data => "GET / HTTP/1.0\er\en\er\en", \& stdout_file => "/tmp/$server.res"}, \& $server, 80) \& or die "unable to retrieve page: " . $ssh\->error; .Ve .PP or capturing the output of several requests in parallel: .PP .Vb 10 \& my @pids; \& for (@servers) { \& my $pid = $ssh\->spawn({tunnel => 1, \& stdin_file => "/tmp/request.req", \& stdout_file => "/tmp/$_.res"}, \& $_, 80); \& if ($pid) { \& push @pids, $pid; \& } \& else { \& warn "unable to spawn tunnel process to $_: " . $ssh\->error; \& } \& } \& waitpid ($_, 0) for (@pids); .Ve .PP Under the hood, in order to create a tunnel, a new \f(CW\*(C`ssh\*(C'\fR process is spawned with the option \f(CW\*(C`\-W${address}:${port}\*(C'\fR (available from OpenSSH 5.4 and upwards) making it redirect its stdio streams to the remote given address. Unlike when \f(CW\*(C`ssh\*(C'\fR \f(CW\*(C`\-L\*(C'\fR options is used to create tunnels, no TCP port is opened on the local machine at any time so this is a perfectly secure operation. .PP The PID of the new process is returned by the named methods. It must be reaped once the pipe or socket handlers for the local side of the tunnel have been closed. .PP OpenSSH 5.4 or later is required for the tunnels functionality to work. Also, note that tunnel forwarding may be administratively forbidden at the server side (see \fBsshd\fR\|(8) and \fBsshd_config\fR\|(5) or the documentation provided by your SSH server vendor). .PP \fITunnels targeting UNIX sockets\fR .IX Subsection "Tunnels targeting UNIX sockets" .PP When connecting to hosts running a recent version of OpenSSH sshd, it is also possible to open connections targeting Unix sockets. .PP For instance: .PP .Vb 2 \& my $response = $ssh\->capture({tunnel => 1, stdin_data => $request }, \& "/tmp/socket\-foo"); .Ve .PP Currently, this feature requires a patched OpenSSH ssh client. The patch is available as \&\f(CW\*(C`patches/openssh\-fwd\-stdio\-to\-streamlocal\-1.patch\*(C'\fR. .PP \fIPort forwarding\fR .IX Subsection "Port forwarding" .PP Net::OpenSSH does not offer direct support for handling port forwardings between server and client. But that can be done easily anyway passing custom SSH options to its methods. .PP For instance, tunnel creation options can be passed to the constructor: .PP .Vb 2 \& my $ssh = Net::OpenSSH\->new(... \& master_opts => \-Llocalhost:1234:localhost:3306\*(Aq); .Ve .PP The port forwardings can also be changed for a running SSH connection using a Control command: .PP .Vb 3 \& # setting up a tunnel: \& $ssh\->system({ssh_opts => [\*(Aq\-O\*(Aq,\*(Aqforward\*(Aq, \& \*(Aq\-L127.0.0.1:12345:127.0.0.1:3306\*(Aq]}); \& \& # canceling it: \& $ssh\->system({ssh_opts => [\*(Aq\-O\*(Aq, \*(Aqcancel\*(Aq, \& \*(Aq\-L127.0.0.1:12345:127.0.0.1:3306\*(Aq]}); .Ve .SS "Data encoding" .IX Subsection "Data encoding" Net::OpenSSH has some support for transparently converting the data send or received from the remote server to Perl internal unicode representation. .PP The methods supporting that feature are those that move data from/to Perl data structures (e.g. \f(CW\*(C`capture\*(C'\fR, \f(CW\*(C`capture2\*(C'\fR, \f(CW\*(C`capture_tunnel\*(C'\fR and methods supporting the \f(CW\*(C`stdin_data\*(C'\fR option). Data accessed through pipes, sockets or redirections is not affected by the encoding options. .PP It is also possible to set the encoding of the command and arguments passed to the remote server on the command line. .PP By default, if no encoding option is given on the constructor or on the method calls, Net::OpenSSH will not perform any encoding transformation, effectively processing the data as \f(CW\*(C`latin1\*(C'\fR. .PP When data can not be converted between the Perl internal representation and the selected encoding inside some Net::OpenSSH method, it will fail with an \f(CW\*(C`OSSH_ENCODING_ERROR\*(C'\fR error. .PP The supported encoding options are as follows: .ie n .IP "stream_encoding => $encoding" 4 .el .IP "stream_encoding => \f(CW$encoding\fR" 4 .IX Item "stream_encoding => $encoding" sets the encoding of the data send and received on capture methods. .ie n .IP "argument_encoding => $encoding" 4 .el .IP "argument_encoding => \f(CW$encoding\fR" 4 .IX Item "argument_encoding => $encoding" sets the encoding of the command line arguments .ie n .IP "encoding => $encoding" 4 .el .IP "encoding => \f(CW$encoding\fR" 4 .IX Item "encoding => $encoding" sets both \f(CW\*(C`argument_encoding\*(C'\fR and \f(CW\*(C`stream_encoding\*(C'\fR. .PP The constructor also accepts \f(CW\*(C`default_encoding\*(C'\fR, \&\f(CW\*(C`default_stream_encoding\*(C'\fR and \f(CW\*(C`default_argument_encoding\*(C'\fR that set the defaults. .ie n .SS "Diverting ""new""" .el .SS "Diverting \f(CWnew\fP" .IX Subsection "Diverting new" When a code ref is installed at \f(CW$Net::OpenSSH::FACTORY\fR, calls to new will be diverted through it. .PP That feature can be used to transparently implement connection caching, for instance: .PP .Vb 2 \& my $old_factory = $Net::OpenSSH::FACTORY; \& my %cache; \& \& sub factory { \& my ($class, %opts) = @_; \& my $signature = join("\e0", $class, map { $_ => $opts{$_} }, sort keys %opts); \& my $old = $cache{signature}; \& return $old if ($old and $old\->error != OSSH_MASTER_FAILED); \& local $Net::OpenSSH::FACTORY = $old_factory; \& $cache{$signature} = $class\->new(%opts); \& } \& \& $Net::OpenSSH::FACTORY = \e&factory; .Ve .PP \&... and I am sure it can be abused in several other ways! .SH "3rd PARTY MODULE INTEGRATION" .IX Header "3rd PARTY MODULE INTEGRATION" .SS Expect .IX Subsection "Expect" Sometimes you would like to use Expect to control some program running in the remote host. You can do it as follows: .PP .Vb 3 \& my ($pty, $pid) = $ssh\->open2pty(@cmd) \& or die "unable to run remote command @cmd"; \& my $expect = Expect\->init($pty); .Ve .PP Then, you will be able to use the new Expect object in \f(CW$expect\fR as usual. .SS Net::Telnet .IX Subsection "Net::Telnet" This example is adapted from Net::Telnet documentation: .PP .Vb 7 \& my ($pty, $pid) = $ssh\->open2pty({stderr_to_stdout => 1}) \& or die "unable to start remote shell: " . $ssh\->error; \& my $telnet = Net::Telnet\->new(\-fhopen => $pty, \& \-prompt => \*(Aq/.*\e$ $/\*(Aq, \& \-telnetmode => 0, \& \-cmd_remove_mode => 1, \& \-output_record_separator => "\er"); \& \& $telnet\->waitfor(\-match => $telnet\->prompt, \& \-errmode => "return") \& or die "login failed: " . $telnet\->lastline; \& \& my @lines = $telnet\->cmd("who"); \& \& ... \& \& $telnet\->close; \& waitpid($pid, 0); .Ve .SS "mod_perl and mod_perl2" .IX Subsection "mod_perl and mod_perl2" mod_perl and mod_perl2 tie STDIN and STDOUT to objects that are not backed up by real file descriptors at the operating system level. Net::OpenSSH will fail if any of these handles is used explicitly or implicitly when calling some remote command. .PP The work-around is to redirect them to \f(CW\*(C`/dev/null\*(C'\fR or to some file: .PP .Vb 3 \& open my $def_in, \*(Aq<\*(Aq, \*(Aq/dev/null\*(Aq or die "unable to open /dev/null"; \& my $ssh = Net::OpenSSH\->new($host, \& default_stdin_fh => $def_in); \& \& my $out = $ssh\->capture($cmd1); \& $ssh\->system({stdout_discard => 1}, $cmd2); \& $ssh\->system({stdout_to_file => \*(Aq/tmp/output\*(Aq}, $cmd3); .Ve .PP Also, note that from a security stand point, running \f(CW\*(C`ssh\*(C'\fR from inside the web server process is not a great idea. An attacker exploiting some Apache bug would be able to access the SSH keys and passwords and gain unlimited access to the remote systems. .PP If you can, use a queue (as TheSchwartz) or any other mechanism to execute the ssh commands from another process running under a different user account. .PP At a minimum, ensure that \f(CW\*(C`~www\-data/.ssh\*(C'\fR (or similar) is not accessible through the web server! .SS Net::SFTP::Foreign .IX Subsection "Net::SFTP::Foreign" See method \f(CW\*(C`sftp\*(C'\fR. .SS Net::SSH::Any .IX Subsection "Net::SSH::Any" See method \f(CW\*(C`any\*(C'\fR. .SS Object::Remote .IX Subsection "Object::Remote" See method \f(CW\*(C`object_remote\*(C'\fR. .SS "AnyEvent (and similar frameworks)" .IX Subsection "AnyEvent (and similar frameworks)" Net::OpenSSH provides all the functionality required to be integrated inside event oriented programming framework such as AnyEvent or IO::Async in the following way: .IX Xref "AnyEvent" .IP "1. Create a disconnected Net::OpenSSH object:" 4 .IX Item "1. Create a disconnected Net::OpenSSH object:" .Vb 1 \& my $ssh = Net::OpenSSH\->new($host, async => 1, ...); .Ve .IP "2. Let the object connect to the remote host:" 4 .IX Item "2. Let the object connect to the remote host:" Use a timer to call the \f(CW\*(C`wait_for_master\*(C'\fR method in async mode repeatedly until it returns a true value indicating success. .Sp Also, the object error state needs to be checked after every call in order to detect failed connections. For instance: .Sp .Vb 10 \& my $ssh = Net::OpenSSH\->new(..., async => 1); \& my $w; \& $w = AE::timer 0.1, 0.1, sub { \& if ($ssh\->wait_for_master(1)) { \& # the connection has been established! \& # remote commands can be run now \& undef $w; \& on_ssh_success(...); \& } \& elsif ($ssh\->error) { \& # connection can not be established \& undef $w; \& on_ssh_failure(...); \& } \& } .Ve .IP "3. Use the event framework to launch the remote processes:" 4 .IX Item "3. Use the event framework to launch the remote processes:" Call Net::OpenSSH \f(CW\*(C`make_remote_command\*(C'\fR to construct commands which can be run using the framework regular facilities for launching external commands. .Sp Error checking should also be performed at this point because the SSH connection could be broken. .Sp For instance: .Sp .Vb 6 \& if (defined(my $cmd = $ssh\->make_remote_command(echo => \*(Aqhello!\*(Aq)) { \& AnyEvent::Util::run_cmd($cmd, %run_cmd_opts); \& } \& else { \& # something went wrong! \& } .Ve .Sp Alternatively, any of the \f(CW\*(C`open*\*(C'\fR methods provided by Net::OpenSSH could also be used to launch remote commands. .IP "4. When finished, disconnect asynchronously" 4 .IX Item "4. When finished, disconnect asynchronously" After initiating an asynchronous disconnect with \f(CWdisconnect(1)\fR, repeatedly call \f(CW\*(C`wait_for_master\*(C'\fR until you get a defined but false value: .Sp .Vb 1 \& $ssh\->disconnect(1); \& \& my $w; $w = AE::timer 0.1, 0.1, sub { \& my $res = $ssh\->wait_for_master(1); \& \& if (defined $res && !$res) { \& undef $w; \& undef $ssh; \& } \& }; .Ve .Sp Be careful not to let the \f(CW$ssh\fR object go out of scope until the disconnection has finished, otherwise its destructor will wait and block your program until the disconnection has completed. .SS "Other modules" .IX Subsection "Other modules" CPAN contains several modules that rely on SSH to perform their duties as for example IPC::PerlSSH or GRID::Machine. .PP Often, it is possible to instruct them to go through a Net::OpenSSH multiplexed connection employing some available constructor option. For instance: .PP .Vb 7 \& use Net::OpenSSH; \& use IPC::PerlIPC; \& my $ssh = Net::OpenSSH\->new(...); \& $ssh\->error and die "unable to connect to remote host: " . $ssh\->error; \& my @cmd = $ssh\->make_remote_command(\*(Aq/usr/bin/perl\*(Aq); \& my $ipc = IPC::PerlSSH\->new(Command => \e@cmd); \& my @r = $ipc\->eval(\*(Aq...\*(Aq); .Ve .PP or... .PP .Vb 5 \& use GRID::Machine; \& ... \& my @cmd = $ssh\->make_remote_command(\*(Aq/usr/bin/perl\*(Aq); \& my $grid = GRID::Machine\->new(command => \e@cmd); \& my $r = $grid\->eval(\*(Aqprint "hello world!\en"\*(Aq); .Ve .PP In other cases, some kind of plugin mechanism is provided by the 3rd party modules to allow for different transports. The method \f(CW\*(C`open2\*(C'\fR may be used to create a pair of pipes for transport in these cases. .SH TROUBLESHOOTING .IX Header "TROUBLESHOOTING" Usually, Net::OpenSSH works out of the box, but when it fails, some users have a hard time finding the cause of the problem. This mini troubleshooting guide should help you to find and solve it. .IP "1 \- check the error message" 4 .IX Item "1 - check the error message" Add in your script, after the Net::OpenSSH constructor call, an error check: .Sp .Vb 2 \& $ssh = Net::OpenSSH\->new(...); \& $ssh\->error and die "SSH connection failed: " . $ssh\->error; .Ve .Sp The error message will tell what has gone wrong. .IP "2 \- Check the connection parameters" 4 .IX Item "2 - Check the connection parameters" Believe it or not, passing bad parameters to Net::OpenSSH turns to be one of the top causes of failures so check that you are using the right parameters. .Sp Specifically, if you are obtaining them from the outside, ensure that they don't have extra spaces or new lines attached (do you need to \&\f(CW\*(C`chomp\*(C'\fR?). .Sp Passwords and URIs may contain \f(CW\*(C`$\*(C'\fR or \f(CW\*(C`@\*(C'\fR characters. If you have then hardcoded in your script, check that those are quoted properly (and BTW, use \f(CW\*(C`strict\*(C'\fR). .IP "3 \- OpenSSH version" 4 .IX Item "3 - OpenSSH version" Ensure that you have a version of \f(CW\*(C`ssh\*(C'\fR recent enough: .Sp .Vb 2 \& $ ssh \-V \& OpenSSH_5.1p1 Debian\-5, OpenSSL 0.9.8g 19 Oct 2007 .Ve .Sp OpenSSH version 4.1 was the first to support the multiplexing feature and is the minimal required by the module to work. I advise you to use the latest OpenSSH (currently 7.5). .Sp The \f(CW\*(C`ssh_cmd\*(C'\fR constructor option lets you select the \f(CW\*(C`ssh\*(C'\fR binary to use. For instance: .Sp .Vb 2 \& $ssh = Net::OpenSSH\->new($host, \& ssh_cmd => "/opt/OpenSSH/5.8/bin/ssh") .Ve .Sp Some hardware vendors (e.g. Sun, err... Oracle) include custom versions of OpenSSH bundled with the operating system. In principle, Net::OpenSSH should work with these SSH clients as long as they are derived from some version of OpenSSH recent enough. Anyway, my advise is to use the real OpenSSH software if you can! .IP "4 \- run ssh from the command line" 4 .IX Item "4 - run ssh from the command line" Check you can connect to the remote host using the same parameters you are passing to Net::OpenSSH. In particular, ensure that you are running \f(CW\*(C`ssh\*(C'\fR as the same local user. .Sp If you are running your script from a web server, the user would probably be \f(CW\*(C`www\*(C'\fR, \f(CW\*(C`apache\*(C'\fR or something alike. .Sp Common problems are: .RS 4 .IP \(bu 4 Remote host public key not present in known_hosts file. .Sp The SSH protocol uses public keys to identify the remote hosts so that they can not be supplanted by some malicious third parties. .Sp For OpenSSH, usually the server public key is stored in \&\f(CW\*(C`/etc/ssh/ssh_host_dsa_key.pub\*(C'\fR or in \&\f(CW\*(C`/etc/ssh/ssh_host_rsa_key.pub\*(C'\fR and that key should be copied into the \&\f(CW\*(C`~/.ssh/known_hosts\*(C'\fR file in the local machine (other SSH implementations may use other file locations). .Sp Maintaining the server keys when several hosts and clients are involved may be somewhat inconvenient, so most SSH clients, by default, when a new connection is established to a host whose key is not in the \f(CW\*(C`known_hosts\*(C'\fR file, show the key and ask the user if he wants the key copied there. .IP \(bu 4 Wrong remote host public key in known_hosts file. .Sp This is another common problem that happens when some server is replaced or reinstalled from scratch and its public key changes becoming different to that installed on the \f(CW\*(C`known_hosts\*(C'\fR file. .Sp The easiest way to solve that problem is to remove the old key from the \f(CW\*(C`known_hosts\*(C'\fR file by hand using any editor and then to connect to the server replying \f(CW\*(C`yes\*(C'\fR when asked to save the new key. .IP \(bu 4 Wrong permissions for the \f(CW\*(C`~/.ssh\*(C'\fR directory or its contents. .Sp OpenSSH client performs several checks on the access permissions of the \f(CW\*(C`~/.ssh\*(C'\fR directory and its contents and refuses to use them when misconfigured. See the FILES section from the \fBssh\fR\|(1) man page. .IP \(bu 4 Incorrect settings for password or public key authentication. .Sp Check that you are using the right password or that the user public key is correctly installed on the server. .RE .RS 4 .RE .IP "5 \- security checks on the multiplexing socket" 4 .IX Item "5 - security checks on the multiplexing socket" Net::OpenSSH performs some security checks on the directory where the multiplexing socket is going to be placed to ensure that it can not be accessed by other users. .Sp The default location for the multiplexing socket is under \&\f(CW\*(C`~/.libnet\-openssh\-perl\*(C'\fR. It can be changed using the \f(CW\*(C`ctl_dir\*(C'\fR and \&\f(CW\*(C`ctl_path\*(C'\fR constructor arguments. .Sp The requirements for that directory and all its parents are: .RS 4 .IP \(bu 4 They have to be owned by the user executing the script or by root .IP \(bu 4 Their permission masks must be 0755 or more restrictive, so nobody else has permissions to perform write operations on them. .RE .RS 4 .Sp The constructor option \f(CW\*(C`strict_mode\*(C'\fR disables these security checks, but you should not use it unless you understand its implications. .RE .IP "6 \- file system must support sockets" 4 .IX Item "6 - file system must support sockets" Some file systems (as for instance FAT or AFS) do not support placing sockets inside them. .Sp Ensure that the \f(CW\*(C`ctl_dir\*(C'\fR path does not lay into one of those file systems. .SH DEBUGGING .IX Header "DEBUGGING" Debugging of Net::OpenSSH internals is controlled through the variable \&\f(CW$Net::OpenSSH::debug\fR. Every bit of this variable activates debugging of some subsystem as follows: .IP "bit 1 \- errors" 4 .IX Item "bit 1 - errors" Dumps changes on the internal object attribute where errors are stored. .IP "bit 2 \- ctl_path" 4 .IX Item "bit 2 - ctl_path" Dumps information about ctl_path calculation and the tests performed on that directory in order to decide if it is secure to place the multiplexing socket inside. .IP "bit 4 \- connecting" 4 .IX Item "bit 4 - connecting" Dumps information about the establishment of new master connections. .IP "bit 8 \- commands and arguments" 4 .IX Item "bit 8 - commands and arguments" Dumps the command and arguments for every system/exec call. .IP "bit 16 \- command execution" 4 .IX Item "bit 16 - command execution" Dumps information about the progress of command execution. .IP "bit 32 \- destruction" 4 .IX Item "bit 32 - destruction" Dumps information about the destruction of Net::OpenSSH objects and the termination of the SSH master processes. .IP "bit 64 \- IO loop" 4 .IX Item "bit 64 - IO loop" Dumps information about the progress of the IO loop on capture operations. .IP "bit 128 \- IO hexdumps" 4 .IX Item "bit 128 - IO hexdumps" Generates hexdumps of the information that travels through the SSH streams inside capture operations. .IP "bit 512 \- OS tracing of the master process" 4 .IX Item "bit 512 - OS tracing of the master process" Use the module Net::OpenSSH::OSTracer to trace the SSH master process at the OS level. .PP For instance, in order to activate all the debugging flags, you can use: .PP .Vb 1 \& $Net::OpenSSH::debug = ~0; .Ve .PP Note that the meaning of the flags and the information generated is only intended for debugging of the module and may change without notice between releases. .PP If you are using password authentication, enabling debugging for IO::Tty may also show interesting information: .PP .Vb 1 \& $IO::Tty::DEBUG = 1; .Ve .PP Finally, by default debugging output is sent to \f(CW\*(C`STDERR\*(C'\fR. You can override it pointing \f(CW$Net::OpenSSH::debug_fh\fR to a different file handle. For instance: .PP .Vb 5 \& BEGIN { \& open my $out, \*(Aq>\*(Aq, \*(Aq/tmp/debug.txt\*(Aq or warn $!; \& $Net::OpenSSH::debug_fh = $out; \& $Net::OpenSSH::debug = \-1; \& } .Ve .SH SECURITY .IX Header "SECURITY" \&\fBQ\fR: Is this module secure? .PP \&\fBA\fR: Well, it tries to be! .PP From a security standpoint the aim of this module is to be as secure as OpenSSH, your operating system, your shell and in general your environment allow it to be. .PP It does not take any shortcut just to make your life easier if that means lowering the security level (for instance, disabling \&\f(CW\*(C`StrictHostKeyChecking\*(C'\fR by default). .PP In code supporting features that are not just proxied to OpenSSH, the module tries to keep the same standards of security as OpenSSH (for instance, checking directory and file permissions when placing the multiplexing socket). .PP On the other hand, and keeping with OpenSSH philosophy, the module lets you disable most (all?) of those security measures. But just because it lets you do it it doesn't mean it is a good idea to do so!!! .PP If you are a novice programmer or SSH user, and googling you have just found some flag that you don't understand but that seems to magically solve your connection problems... well, believe me, it is probably a bad idea to use it. Ask somebody how really knows first! .PP Just to make thinks clear, if your code contains any of the keywords from the (non-exclusive) list below and you don't know why, you are probably wrecking the security of the SSH protocol: .PP .Vb 3 \& strict_mode \& StrictHostKeyChecking \& UserKnownHostsFile .Ve .PP Other considerations related to security you may like to know are as follows: .IP "Taint mode" 4 .IX Item "Taint mode" The module supports working in taint mode. .Sp If you are in an exposed environment, you should probably enable it for your script in order to catch any unchecked command for being executed in the remote side. .IP "Web environments" 4 .IX Item "Web environments" It is a bad idea to establish SSH connections from your webserver because if it becomes compromised in any way, the attacker would be able to use the credentials from your script to connect to the remote host and do anything he wishes there. .IP "Command quoting" 4 .IX Item "Command quoting" The module can quote commands and arguments for you in a flexible and powerful way. .Sp This is a feature you should use as it reduces the possibility of some attacker being able to inject and run arbitrary commands on the remote machine (and even for scripts that are not exposed it is always advisable to enable argument quoting). .Sp Having said that, take into consideration that argument-quoting is just a hack to emulate the invoke-without-a-shell feature of Perl builtins such as \f(CW\*(C`system\*(C'\fR and alike. There may be bugs(*) on the quoting code, your particular shell may have different quoting rules with unhandled corner cases or whatever. If your script is exposed to the outside, you should check your inputs and restrict what you accept as valid. .Sp [* even if this is one of the parts of the module more intensively tested!] .IP Shellshock 4 .IX Item "Shellshock" (see Shellshock ) .Sp When executing local commands, the module always avoids calling the shell so in this way it is not affected by Shellshock. .Sp Unfortunately, some commands (\f(CW\*(C`scp\*(C'\fR, \f(CW\*(C`rsync\*(C'\fR and \f(CW\*(C`ssh\*(C'\fR when the \&\f(CW\*(C`ProxyCommand\*(C'\fR option is used) invoke other commands under the hood using the user shell. That opens the door to local Shellshock exploitation. .Sp On the remote side invocation of the shell is unavoidable due to the protocol design. .Sp By default, SSH does not forward environment variables but some Linux distributions explicitly change the default OpenSSH configuration to enable forwarding and acceptance of some specific ones (for instance \&\f(CW\*(C`LANG\*(C'\fR and \f(CW\*(C`LC_*\*(C'\fR on Debian and derivatives, Fedora does alike) and this also opens the door to Shellshock exploitation. .Sp Note that the shell used to invoke commands is not \f(CW\*(C`/bin/sh\*(C'\fR but the user shell as configured in \f(CW\*(C`/etc/passwd\*(C'\fR, PAM or whatever authentication subsystem is used by the local or remote operating system. Debian users, don't think you are not affected because your \f(CW\*(C`/bin/sh\*(C'\fR points to \f(CW\*(C`dash\*(C'\fR! .SH FAQ .IX Header "FAQ" Frequent questions about the module: .IP "Connecting to switches, routers, etc." 4 .IX Item "Connecting to switches, routers, etc." \&\fBQ\fR: I can not get the method \f(CW\*(C`system\*(C'\fR, \f(CW\*(C`capture\*(C'\fR, etc., to work when connecting to some router, switch, etc. What I am doing wrong? .Sp \&\fBA\fR: Roughly, the SSH protocol allows for two modes of operation: command mode and interactive mode. .Sp Command mode is designed to run single commands on the remote host. It opens a SSH channel between both hosts, asks the remote computer to run some given command and when it finishes, the channel is closed. It is what you get, for instance, when you run something as... .Sp .Vb 1 \& $ ssh my.unix.box cat foo.txt .Ve .Sp \&... and it is also the way Net::OpenSSH runs commands on the remote host. .Sp Interactive mode launches a shell on the remote hosts with its stdio streams redirected to the local ones so that the user can transparently interact with it. .Sp Some devices (as probably the one you are using) do not run an standard, general purpose shell (e.g. \f(CW\*(C`bash\*(C'\fR, \f(CW\*(C`csh\*(C'\fR or \f(CW\*(C`ksh\*(C'\fR) but some custom program specially targeted and limited to the task of configuring the device. .Sp Usually, the SSH server running on these devices does not support command mode. It unconditionally attaches the restricted shell to any incoming SSH connection and waits for the user to enter commands through the redirected stdin stream. .Sp The only way to work-around this limitation is to make your script talk to the restricted shell (1\-open a new SSH session, 2\-wait for the shell prompt, 3\-send a command, 4\-read the output until you get to the shell prompt again, repeat from 3). The best tool for this task is probably Expect, used alone or combined with Net::OpenSSH (see "Expect"). .Sp There are some devices that support command mode but that only accept one command per connection. In that cases, using Expect is also probably the best option. .Sp Nowadays, there is a new player, Net::CLI::Interact that may be more suitable than Expect, and Net::Appliance::Session for working specifically with network devices. .IP "Connection fails" 4 .IX Item "Connection fails" \&\fBQ\fR: I am unable to make the module connect to the remote host... .Sp \&\fBA\fR: Have you read the troubleshooting section? (see "TROUBLESHOOTING"). .IP "Disable StrictHostKeyChecking" 4 .IX Item "Disable StrictHostKeyChecking" \&\fBQ\fR: Why is \f(CW\*(C`ssh\*(C'\fR not run with \f(CW\*(C`StrictHostKeyChecking=no\*(C'\fR? .Sp \&\fBA\fR: Using \f(CW\*(C`StrictHostKeyChecking=no\*(C'\fR relaxes the default security level of SSH and it will be relatively easy to end with a misconfigured SSH (for instance, when \f(CW\*(C`known_hosts\*(C'\fR is unwritable) that could be forged to connect to a bad host in order to perform man-in-the-middle attacks, etc. .Sp I advice you to do not use that option unless you fully understand its implications from a security point of view. .Sp If you want to use it anyway, past it to the constructor: .Sp .Vb 3 \& $ssh = Net::OpenSSH\->new($host, \& master_opts => [\-o => "StrictHostKeyChecking=no"], \& ...); .Ve .IP "child process STDIN/STDOUT/STDERR is not a real system file handle" 4 .IX Item "child process STDIN/STDOUT/STDERR is not a real system file handle" \&\fBQ\fR: Calls to \f(CW\*(C`system\*(C'\fR, \f(CW\*(C`capture\*(C'\fR, etc. fail with the previous error, what's happening? .Sp \&\fBA\fR: The reported stdio stream is closed or is not attached to a real file handle (e.g. it is a tied handle). Redirect it to \f(CW\*(C`/dev/null\*(C'\fR or to a real file: .Sp .Vb 2 \& my $out = $ssh\->capture({stdin_discard => 1, stderr_to_stdout => 1}, \& $cmd); .Ve .Sp See also the mod_perl entry above. .IP "Solaris (and AIX and probably others)" 4 .IX Item "Solaris (and AIX and probably others)" \&\fBQ\fR: I was trying Net::OpenSSH on Solaris and seem to be running into an issue... .Sp \&\fBA\fR: The SSH client bundled with Solaris is an early fork of OpenSSH that does not provide the multiplexing functionality required by Net::OpenSSH. You will have to install the OpenSSH client. .Sp Precompiled packages are available from Sun Freeware (). There, select your OS version an CPU architecture, download the OpenSSH package and its dependencies and install them. Note that you do \fBnot\fR need to configure Solaris to use the OpenSSH server \f(CW\*(C`sshd\*(C'\fR. .Sp Ensure that OpenSSH client is in your path before the system \f(CW\*(C`ssh\*(C'\fR or alternatively, you can hardcode the full path into your scripts as follows: .Sp .Vb 2 \& $ssh = Net::OpenSSH\->new($host, \& ssh_cmd => \*(Aq/usr/local/bin/ssh\*(Aq); .Ve .Sp AIX and probably some other unixen, also bundle SSH clients lacking the multiplexing functionality and require installation of the real OpenSSH. .IP "Can not change working directory" 4 .IX Item "Can not change working directory" \&\fBQ\fR: I want to run some command inside a given remote directory but I am unable to change the working directory. For instance: .Sp .Vb 2 \& $ssh\->system(\*(Aqcd /home/foo/bin\*(Aq); \& $ssh\->systen(\*(Aqls\*(Aq); .Ve .Sp does not list the contents of \f(CW\*(C`/home/foo/bin\*(C'\fR. .Sp What am I doing wrong? .Sp \&\fBA\fR: Net::OpenSSH (and, for that matter, all the SSH modules available from CPAN but Net::SSH::Expect) run every command in a new session so most shell builtins that are run for its side effects become useless (e.g. \f(CW\*(C`cd\*(C'\fR, \f(CW\*(C`export\*(C'\fR, \f(CW\*(C`ulimit\*(C'\fR, \f(CW\*(C`umask\*(C'\fR, etc., usually, you can list them running \f(CW\*(C`help\*(C'\fR from the shell). .Sp A work around is to combine several commands in one, for instance: .Sp .Vb 1 \& $ssh\->system(\*(Aqcd /home/foo/bin && ls\*(Aq); .Ve .Sp Note the use of the shell \f(CW\*(C`&&\*(C'\fR operator instead of \f(CW\*(C`;\*(C'\fR in order to abort the command as soon as any of the subcommands fail. .Sp Also, several commands can be combined into one while still using the multi-argument quoting feature as follows: .Sp .Vb 1 \& $ssh\->system(@cmd1, \e\e\*(Aq&&\*(Aq, @cmd2, \e\e\*(Aq&&\*(Aq, @cmd3, ...); .Ve .IP "Running detached remote processes" 4 .IX Item "Running detached remote processes" \&\fBQ\fR: I need to be able to ssh into several machines from my script, launch a process to run in the background there, and then return immediately while the remote programs keep running... .Sp \&\fBA\fR: If the remote systems run some Unix/Linux variant, the right approach is to use \fBnohup\fR\|(1) that will disconnect the remote process from the stdio streams and to ask the shell to run the command on the background. For instance: .Sp .Vb 1 \& $ssh\->system("nohup $long_running_command &"); .Ve .Sp Also, it may be possible to demonize the remote program. If it is written in Perl you can use App::Daemon for that (actually, there are several CPAN modules that provided that kind of functionality). .Sp In any case, note that you should not use "spawn" for that. .IP "MaxSessions server limit reached" 4 .IX Item "MaxSessions server limit reached" \&\fBQ\fR: I created an \f(CW$ssh\fR object and then fork a lot children processes which use this object. When the children number is bigger than \f(CW\*(C`MaxSessions\*(C'\fR as defined in sshd configuration (defaults to 10), trying to fork new remote commands will prompt the user for the password. .Sp \&\fBA\fR: When the slave SSH client gets a response from the remote servers saying that the maximum number of sessions for the current connection has been reached, it fall backs to open a new direct connection without going through the multiplexing socket. .Sp To stop that for happening, the following hack can be used: .Sp .Vb 3 \& $ssh = Net::OpenSSH\->new(host, \& default_ssh_opts => [\*(Aq\-oConnectionAttempts=0\*(Aq], \& ...); .Ve .IP "Running remote commands with sudo" 4 .IX Item "Running remote commands with sudo" \&\fBQ\fR: How can I run remote commands using \f(CW\*(C`sudo\*(C'\fR to become root first? .Sp \&\fBA\fR: The simplest way is to tell \f(CW\*(C`sudo\*(C'\fR to read the password from stdin with the \f(CW\*(C`\-S\*(C'\fR flag and to do not use cached credentials with the \f(CW\*(C`\-k\*(C'\fR flag. You may also like to use the \f(CW\*(C`\-p\*(C'\fR flag to tell \&\f(CW\*(C`sudo\*(C'\fR to print an empty prompt. For instance: .Sp .Vb 5 \& my @out = $ssh\->capture({ stdin_data => "$sudo_passwd\en" }, \& \*(Aqsudo\*(Aq, \*(Aq\-Sk\*(Aq, \& \*(Aq\-p\*(Aq, \*(Aq\*(Aq, \& \*(Aq\-\-\*(Aq, \& @cmd); .Ve .Sp If the version of sudo installed on the remote host does not support the \f(CW\*(C`\-S\*(C'\fR flag (it tells sudo to read the password from its STDIN stream), you can do it as follows: .Sp .Vb 6 \& my @out = $ssh\->capture({ tty => 1, \& stdin_data => "$sudo_passwd\en" }, \& \*(Aqsudo\*(Aq, \*(Aq\-k\*(Aq, \& \*(Aq\-p\*(Aq, \*(Aq\*(Aq, \& \*(Aq\-\-\*(Aq, \& @cmd); .Ve .Sp This may generate an spurious and harmless warning from the SSH master connection (because we are requesting allocation of a tty on the remote side and locally we are attaching it to a regular pair of pipes). .Sp If for whatever reason the methods described above fail, you can always revert to using Expect to talk to the remote \f(CW\*(C`sudo\*(C'\fR. See the \&\f(CW\*(C`examples/expect.pl\*(C'\fR script from this module distribution. .IP "Interactive sessions" 4 .IX Item "Interactive sessions" \&\fBQ\fR: How can I start an interactive remote session? .Sp \&\fBA\fR: Just call the \f(CW\*(C`system\*(C'\fR method with an empty argument list: .Sp .Vb 2 \& my $ssh = Net::OpenSSH\->new(...); \& $ssh\->system; .Ve .Sp \&\fBQ\fR: How about running an interactive \f(CW\*(C`sftp\*(C'\fR session? .Sp \&\fBA\fR: Programs that use an underlying ssh connection usually provide some way (for instance, command line option \f(CW\*(C`\-o\*(C'\fR) to pass additional options for the \f(CW\*(C`ssh\*(C'\fR command used to run that connection. We just need to use such mechanism to pass the path to the control socket. .Sp For instance, for the particular case of \f(CW\*(C`sftp\*(C'\fR: .Sp .Vb 2 \& $cp = $ssh\->get_ctl_path; \& system "sftp", "\-oControlPath=$cp", $host; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" OpenSSH client documentation \fBssh\fR\|(1), \fBssh_config\fR\|(5), the project web and its FAQ . \fBscp\fR\|(1) and \&\fBrsync\fR\|(1). The OpenSSH Wikibook . .PP Net::OpenSSH::Gateway for detailed instruction about how to get this module to connect to hosts through proxies and other SSH gateway servers. .PP Core perl documentation perlipc, "open" in perlfunc, "waitpid" in perlfunc. .PP IO::Pty to known how to use the pseudo tty objects returned by several methods on this package. .PP Net::SFTP::Foreign provides a compatible SFTP implementation. .PP Expect can be used to interact with commands run through this module on the remote machine (see also the \f(CW\*(C`expect.pl\*(C'\fR and scripts in the examples directory). .PP SSH::OpenSSH::Parallel is an advanced scheduler that allows one to run commands in remote hosts in parallel. It is obviously based on Net::OpenSSH. .PP SSH::Batch allows one to run remote commands in parallel in a cluster. It is build on top on \f(CW\*(C`Net::OpenSSH\*(C'\fR also. .PP Other Perl SSH clients: Net::SSH::Perl, Net::SSH2, Net::SSH, Net::SSH::Expect, Net::SCP, Net::SSH::Mechanize. .PP Net::OpenSSH::Compat is a package offering a set of compatibility layers for other SSH modules on top of Net::OpenSSH. .PP IPC::PerlSSH, GRID::Machine allow execution of Perl code in remote machines through SSH. .PP SSH::RPC implements an RPC mechanism on top of SSH using Net::OpenSSH to handle the connections. .PP Net::CLI::Interact allows one to interact with remote shells and other services. It is specially suited for interaction with network equipment. The phrasebook approach it uses is very clever. You may also like to check the other modules from its author, Oliver Gorwits. .SH "BUGS AND SUPPORT" .IX Header "BUGS AND SUPPORT" .SS "Experimental features" .IX Subsection "Experimental features" Support for the \f(CW\*(C`restart\*(C'\fR feature is experimental. .PP Object::Remote integration is highly experimental. .PP Support for tunnels targeting Unix sockets is highly experimental. .PP Support for the \f(CW\*(C`setpgrp\*(C'\fR feature is highly experimental. .PP Support for the gateway feature is highly experimental and mostly stalled. .PP Support for taint mode is experimental. .SS "Known issues" .IX Subsection "Known issues" Net::OpenSSH does not work on Windows. OpenSSH multiplexing feature requires passing file handles through sockets, something that is not supported by any version of Windows. .PP It does not work on VMS either... well, probably, it does not work on anything not resembling a modern Linux/Unix OS. .PP Old versions of OpenSSH \f(CW\*(C`ssh\*(C'\fR may leave stdio streams in non-blocking mode. That can result on failures when writing to \f(CW\*(C`STDOUT\*(C'\fR or \&\f(CW\*(C`STDERR\*(C'\fR after using the module. In order to work-around this issue, Perl "fcntl" in perlfunc can be used to unset the non-blocking flag: .PP .Vb 3 \& use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); \& my $flags = fcntl(STDOUT, F_GETFL, 0); \& fcntl(STDOUT, F_SETFL, $flags & ~O_NONBLOCK); .Ve .SS "Reporting bugs and asking for help" .IX Subsection "Reporting bugs and asking for help" To report bugs send an email to the address that appear below or use the CPAN bug tracking system at . .PP \&\fBPost questions related to how to use the module in PerlMonks\fR , you will probably get faster responses than if you address me directly and I visit PerlMonks quite often, so I will see your question anyway. .SS "Commercial support" .IX Subsection "Commercial support" Commercial support, professional services and custom software development around this module are available through my current company. Drop me an email with a rough description of your requirements and we will get back to you ASAP. .SS "My wishlist" .IX Subsection "My wishlist" If you like this module and you are feeling generous, take a look at my Amazon Wish List: . .PP Also consider contributing to the OpenSSH project this module builds upon: . .SH TODO .IX Header "TODO" \&\- Tests for \f(CW\*(C`scp_*\*(C'\fR, \f(CW\*(C`rsync_*\*(C'\fR and \f(CW\*(C`sftp\*(C'\fR methods .PP \&\- Make "pipe_in" and "pipe_out" methods "open_ex" based .PP \&\- \f(CW\*(C`auto_discard_streams\*(C'\fR feature for mod_perl2 and similar environments .PP \&\- Refactor open_ex support for multiple commands, maybe just keeping tunnel, ssh and raw .PP Send your feature requests, ideas or any feedback, please! .SH "CONTRIBUTING CODE" .IX Header "CONTRIBUTING CODE" The source code of this module is hosted at GitHub: . .PP Code contributions to the module are welcome but you should obey the following rules: .IP "Only Perl 5.8.4 required" 4 .IX Item "Only Perl 5.8.4 required" Yes, that's pretty old, but Net::OpenSSH is intended to be also used by system administrators that sometimes have to struggle with old systems. The reason to pick 5.8.4 is that it has been the default perl on Solaris for a long time. .IP "Avoid the ""All the world's a Linux PC"" syndrome" 4 .IX Item "Avoid the ""All the world's a Linux PC"" syndrome" The module should work on any (barely) sane Unix or Linux operating system. Specially, it should not be assumed that the over-featured GNU utilities and toolchain are available. .IP "Dependencies are optional" 4 .IX Item "Dependencies are optional" In order to make the module very easy to install, no mandatory dependencies on other CPAN modules are allowed. .Sp Optional modules, that are loaded only on demand, are acceptable when they are used for adding new functionality (as it is done, for instance, with IO::Pty). .Sp Glue code for integration with 3rd party modules is also allowed (as it is done with Expect). .Sp Usage of language extension modules and alike is not acceptable. .IP "Tests should be lax" 4 .IX Item "Tests should be lax" We don't want false negatives when testing. In case of doubt tests should succeed. .Sp Also, in case of tests invoking some external program, it should be checked that the external program is available and that it works as expected or otherwise skip those tests. .IP "Backward compatibility" 4 .IX Item "Backward compatibility" Nowadays Net::OpenSSH is quite stable and there are lots of scripts out there using it that we don't want to break, so, keeping the API backward compatible is a top priority. .Sp Probably only security issues could now justify a backward incompatible change. .IP "Follow my coding style" 4 .IX Item "Follow my coding style" Look at the rest of the code. .Sp I let Emacs do the formatting for me using cperl-mode PerlStyle. .IP "Talk to me" 4 .IX Item "Talk to me" Before making a large change or implementing a new feature get in touch with me. .Sp I may have my own ideas about how things should be done. It is better if you know them before hand, otherwise, you risk getting your patch rejected. .PP Well, actually you should know that I am quite good at rejecting patches but it is not my fault! .PP Most of the patches I get are broken in some way: they don't follow the main module principles, sometimes the author didn't get the full picture and solved the issue in a short-sighted way, etc. .PP In any case, you should not be discouraged to contribute. Even if your patch is not applied directly, seeing how it solves your requirements or, in the case of bugs, the underlying problem analysis may be very useful and help me to do it... my way. .PP I always welcome documentation corrections and improvements. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2008\-2022 by Salvador FandiƱo (sfandino@yahoo.com) .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.