.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "SSH 3pm" .TH SSH 3pm "2022-12-12" "perl v5.36.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::SSH \- Perl extension for secure shell .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::SSH qw(ssh ssh_cmd issh sshopen2 sshopen3); \& \& ssh(\*(Aquser@hostname\*(Aq, $command); \& \& issh(\*(Aquser@hostname\*(Aq, $command); \& \& ssh_cmd(\*(Aquser@hostname\*(Aq, $command); \& ssh_cmd( { \& user => \*(Aquser\*(Aq, \& host => \*(Aqhost.name\*(Aq, \& command => \*(Aqcommand\*(Aq, \& args => [ \*(Aq\-arg1\*(Aq, \*(Aq\-arg2\*(Aq ], \& stdin_string => "string\en", \& } ); \& \& sshopen2(\*(Aquser@hostname\*(Aq, $reader, $writer, $command); \& \& sshopen3(\*(Aquser@hostname\*(Aq, $writer, $reader, $error, $command); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Simple wrappers around ssh commands. .PP For an all-perl implementation that does not require the system \fBssh\fR command, see Net::SSH::Perl instead. .SH "SUBROUTINES" .IX Header "SUBROUTINES" .IP "ssh [USER@]HOST, \s-1COMMAND\s0 [, \s-1ARGS ...\s0 ]" 4 .IX Item "ssh [USER@]HOST, COMMAND [, ARGS ... ]" Calls ssh in batch mode. .IP "issh [USER@]HOST, \s-1COMMAND\s0 [, \s-1ARGS ...\s0 ]" 4 .IX Item "issh [USER@]HOST, COMMAND [, ARGS ... ]" Prints the ssh command to be executed, waits for the user to confirm, and (optionally) executes the command. .IP "ssh_cmd [USER@]HOST, \s-1COMMAND\s0 [, \s-1ARGS ...\s0 ]" 4 .IX Item "ssh_cmd [USER@]HOST, COMMAND [, ARGS ... ]" .PD 0 .IP "ssh_cmd \s-1OPTIONS_HASHREF\s0" 4 .IX Item "ssh_cmd OPTIONS_HASHREF" .PD Calls ssh in batch mode. Throws a fatal error if data occurs on the command's \&\s-1STDERR.\s0 Returns any data from the command's \s-1STDOUT.\s0 .Sp If using the hashref-style of passing arguments, possible keys are: .Sp .Vb 5 \& user (optional) \& host (required) \& command (required) \& args (optional, arrayref) \& stdin_string (optional) \- written to the command\*(Aqs STDIN .Ve .IP "sshopen2 [USER@]HOST, \s-1READER, WRITER, COMMAND\s0 [, \s-1ARGS ...\s0 ]" 4 .IX Item "sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ]" Connects the supplied filehandles to the ssh process (in batch mode). .IP "sshopen3 \s-1HOST, WRITER, READER, ERROR, COMMAND\s0 [, \s-1ARGS ...\s0 ]" 4 .IX Item "sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ]" Connects the supplied filehandles to the ssh process (in batch mode). .SH "EXAMPLE" .IX Header "EXAMPLE" .Vb 2 \& use Net::SSH qw(sshopen2); \& use strict; \& \& my $user = "username"; \& my $host = "hostname"; \& my $cmd = "command"; \& \& sshopen2("$user\e@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; \& \& while () { \& chomp(); \& print "$_\en"; \& } \& \& close(READER); \& close(WRITER); .Ve .SH "FREQUENTLY ASKED QUESTIONS" .IX Header "FREQUENTLY ASKED QUESTIONS" Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? .PP A: You don't (at least not with this module). Use \s-1RSA\s0 or \s-1DSA\s0 keys. See the quick help in the next section and the \fBssh\-keygen\fR\|(1) manpage. .PP A #2: See Net::SSH::Expect instead. .PP Q: My script is \*(L"leaking\*(R" ssh processes. .PP A: See \*(L"How do I avoid zombies on a Unix system\*(R" in perlfaq8, IPC::Open2, IPC::Open3 and \*(L"waitpid\*(R" in perlfunc. .SH "GENERATING AND USING SSH KEYS" .IX Header "GENERATING AND USING SSH KEYS" .IP "1 Generate keys" 4 .IX Item "1 Generate keys" Type: .Sp .Vb 1 \& ssh\-keygen \-t rsa .Ve .Sp And do not enter a passphrase unless you wanted to be prompted for one during file copying. .Sp Here is what you will see: .Sp .Vb 4 \& $ ssh\-keygen \-t rsa \& Generating public/private rsa key pair. \& Enter file in which to save the key (/home/User/.ssh/id_rsa): \& Enter passphrase (empty for no passphrase): \& \& Enter same passphrase again: \& \& Your identification has been saved in /home/User/.ssh/id_rsa. \& Your public key has been saved in /home/User/.ssh/id_rsa.pub. \& The key fingerprint is: \& 5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF\-CPU .Ve .IP "2 Copy public to machines you want to upload to" 4 .IX Item "2 Copy public to machines you want to upload to" \&\f(CW\*(C`id_rsa.pub\*(C'\fR is your public key. Copy it to \f(CW\*(C`~/.ssh\*(C'\fR on target machine. .Sp Put a copy of the public key file on each machine you want to log into. Name the copy \f(CW\*(C`authorized_keys\*(C'\fR (some implementations name this file \&\f(CW\*(C`authorized_keys2\*(C'\fR) .Sp Then type: .Sp .Vb 1 \& chmod 600 authorized_keys .Ve .Sp Then make sure your home dir on the remote machine is not group or world writeable. .SH "AUTHORS" .IX Header "AUTHORS" Ivan Kohler .PP Assistance wanted \- this module could really use a maintainer with enough time to at least review and apply more patches. Or the module should just be deprecated in favor of Net::SSH::Expect or made into an ::Any style compatibility wrapper that uses whatver implementation is available (Net::SSH2, Net::SSH::Perl or shelling out like the module does now). Please email Ivan if you are interested in helping. .PP John Harrison contributed an example for the documentation. .PP Martin Langhoff contributed the ssh_cmd command, and Jeff Finucane updated it and took care of the 0.04 release. .PP Anthony Awtrey contributed a fix for those still using OpenSSH v1. .PP Thanks to terrence brannon for the documentation in the \s-1GENERATING AND USING SSH KEYS\s0 section. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2004 Ivan Kohler. Copyright (c) 2007\-2008 Freeside Internet Services, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "BUGS" .IX Header "BUGS" Not \s-1OO.\s0 .PP Look at IPC::Session (also fsh, well now the native \s-1SSH\s0 \*(L"master mode\*(R" stuff) .SH "SEE ALSO" .IX Header "SEE ALSO" For a perl implementation that does not require the system \fBssh\fR command, see Net::SSH::Perl instead. .PP For a wrapper version that allows you to use passwords, see Net::SSH::Expect instead. .PP For another non-forking version that uses the libssh2 library, see Net::SSH2. .PP For a way to execute remote Perl code over an ssh connection see IPC::PerlSSH. .PP \&\fBssh\-keygen\fR\|(1), \fBssh\fR\|(1), IO::File, IPC::Open2, IPC::Open3