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', $writer, $reader, $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 QUESTIONS
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.
123 Q: My script is "leaking" ssh processes.
125 A: See L<perlfaq8/"How do I avoid zombies on a Unix system">, L<IPC::Open2>,
126 L<IPC::Open3> and L<perlfunc/waitpid>.
130 Ivan Kohler <ivan-netssh_pod@420.am>
134 John Harrison <japh@in-ta.net> contributed an example for the documentation.
138 Copyright (c) 2000 Ivan Kohler.
139 Copyright (c) 2000 Silicon Interactive Software Design.
140 Copyright (c) 2000 Freeside Internet Services, LLC
142 This program is free software; you can redistribute it and/or modify it under
143 the same terms as Perl itself.
149 Look at IPC::Session (also fsh)
153 ssh-keygen(1), ssh(1), L<IPC::Open2>, L<IPC::Open3>