4 use vars qw($VERSION @ISA @EXPORT_OK $ssh);
10 @EXPORT_OK = qw( ssh issh sshopen2 sshopen3 );
17 Net::SSH - Perl extension for secure shell
21 use Net::SSH qw(ssh issh sshopen2 sshopen3);
23 ssh('user@hostname', $command);
25 issh('user@hostname', $command);
27 sshopen2('user@hostname', $reader, $writer, $command);
29 sshopen3('user@hostname', $reader, $writer, $error, $command);
33 Simple wrappers around ssh commands.
39 =item ssh [USER@]HOST, COMMAND [, ARGS ... ]
41 Calls ssh in batch mode.
46 my($host, @command) = @_;
47 my @cmd = ($ssh, '-o', 'BatchMode yes', $host, @command);
51 =item issh [USER@]HOST, COMMAND [, ARGS ... ]
53 Prints the ssh command to be executed, waits for the user to confirm, and
54 (optionally) executes the command.
59 my($host, @command) = @_;
60 my @cmd = ($ssh, $host, @command);
61 print join(' ', @cmd), "\n";
67 =item sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ]
69 Connects the supplied filehandles to the ssh process (in batch mode).
74 my($host, $reader, $writer, @command) = @_;
75 open2($reader, $writer, $ssh, '-o', 'Batchmode yes', $host, @command);
78 =item sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ]
80 Connects the supplied filehandles to the ssh process (in batch mode).
85 my($host, $writer, $reader, $error, @command) = @_;
86 open3($writer, $reader, $error, $ssh, '-o', 'Batchmode yes', $host, @command);
90 print "Proceed [y/N]:";
91 my $x = scalar(<STDIN>);
99 use Net::SSH qw(sshopen2);
102 my $user = "username";
103 my $host = "hostname";
106 sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
116 =head1 FREQUENTLY ASKED QUESTION
118 Q: How do you supply a password to connect with ssh within a perl script
119 using the Net::SSH module?
121 A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage.
125 Ivan Kohler <ivan-netssh_pod@420.am>
129 John Harrison <japh@in-ta.net> contributed an example for the documentation.
135 Look at IPC::Session (also fsh)
139 ssh-keygen(1), ssh(1), L<IPC::Open2>, L<IPC::Open3>