4 use vars qw($VERSION @ISA @EXPORT_OK $ssh $DEBUG);
10 @EXPORT_OK = qw( ssh issh sshopen2 sshopen3 );
19 Net::SSH - Perl extension for secure shell
23 use Net::SSH qw(ssh issh sshopen2 sshopen3);
25 ssh('user@hostname', $command);
27 issh('user@hostname', $command);
29 sshopen2('user@hostname', $reader, $writer, $command);
31 sshopen3('user@hostname', $writer, $reader, $error, $command);
35 Simple wrappers around ssh commands.
41 =item ssh [USER@]HOST, COMMAND [, ARGS ... ]
43 Calls ssh in batch mode.
48 my($host, @command) = @_;
49 my @cmd = ($ssh, '-o', 'BatchMode yes', $host, @command);
50 warn "[Net::SSH::ssh] executing ". join(' ', @cmd). "\n"
55 =item issh [USER@]HOST, COMMAND [, ARGS ... ]
57 Prints the ssh command to be executed, waits for the user to confirm, and
58 (optionally) executes the command.
63 my($host, @command) = @_;
64 my @cmd = ($ssh, $host, @command);
65 print join(' ', @cmd), "\n";
71 =item sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ]
73 Connects the supplied filehandles to the ssh process (in batch mode).
78 my($host, $reader, $writer, @command) = @_;
79 open2($reader, $writer, $ssh, '-o', 'Batchmode yes', $host, @command);
82 =item sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ]
84 Connects the supplied filehandles to the ssh process (in batch mode).
89 my($host, $writer, $reader, $error, @command) = @_;
90 open3($writer, $reader, $error, $ssh, '-o', 'Batchmode yes', $host, @command);
94 print "Proceed [y/N]:";
95 my $x = scalar(<STDIN>);
103 use Net::SSH qw(sshopen2);
106 my $user = "username";
107 my $host = "hostname";
110 sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
120 =head1 FREQUENTLY ASKED QUESTIONS
122 Q: How do you supply a password to connect with ssh within a perl script
123 using the Net::SSH module?
125 A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage.
127 Q: My script is "leaking" ssh processes.
129 A: See L<perlfaq8/"How do I avoid zombies on a Unix system">, L<IPC::Open2>,
130 L<IPC::Open3> and L<perlfunc/waitpid>.
134 Ivan Kohler <ivan-netssh_pod@420.am>
138 John Harrison <japh@in-ta.net> contributed an example for the documentation.
142 Copyright (c) 2000 Ivan Kohler.
143 Copyright (c) 2000 Silicon Interactive Software Design.
144 Copyright (c) 2000 Freeside Internet Services, LLC
146 This program is free software; you can redistribute it and/or modify it under
147 the same terms as Perl itself.
153 Look at IPC::Session (also fsh)
157 ssh-keygen(1), ssh(1), L<IPC::Open2>, L<IPC::Open3>