1SSH(3) User Contributed Perl Documentation SSH(3)
2
3
4
6 Net::SSH - Perl extension for secure shell
7
9 use Net::SSH qw(ssh issh sshopen2 sshopen3);
10
11 ssh('user@hostname', $command);
12
13 issh('user@hostname', $command);
14
15 ssh_cmd('user@hostname', $command);
16 ssh_cmd( {
17 user => 'user',
18 host => 'host.name',
19 command => 'command',
20 args => [ '-arg1', '-arg2' ],
21 stdin_string => "string\n",
22 } );
23
24 sshopen2('user@hostname', $reader, $writer, $command);
25
26 sshopen3('user@hostname', $writer, $reader, $error, $command);
27
29 Simple wrappers around ssh commands.
30
31 For an all-perl implementation that does not require the system ssh
32 command, see Net::SSH::Perl instead.
33
35 ssh [USER@]HOST, COMMAND [, ARGS ... ]
36 Calls ssh in batch mode.
37
38 issh [USER@]HOST, COMMAND [, ARGS ... ]
39 Prints the ssh command to be executed, waits for the user to con‐
40 firm, and (optionally) executes the command.
41
42 ssh_cmd [USER@]HOST, COMMAND [, ARGS ... ]
43 ssh_cmd OPTIONS_HASHREF
44 Calls ssh in batch mode. Throws a fatal error if data occurs on
45 the command's STDERR. Returns any data from the command's STDOUT.
46
47 If using the hashref-style of passing arguments, possible keys are:
48
49 user (optional)
50 host (requried)
51 command (required)
52 args (optional, arrayref)
53 stdin_string (optional) - written to the command's STDIN
54
55 sshopen2 [USER@]HOST, READER, WRITER, COMMAND [, ARGS ... ]
56 Connects the supplied filehandles to the ssh process (in batch
57 mode).
58
59 sshopen3 HOST, WRITER, READER, ERROR, COMMAND [, ARGS ... ]
60 Connects the supplied filehandles to the ssh process (in batch
61 mode).
62
64 use Net::SSH qw(sshopen2);
65 use strict;
66
67 my $user = "username";
68 my $host = "hostname";
69 my $cmd = "command";
70
71 sshopen2("$user\@$host", *READER, *WRITER, "$cmd") ⎪⎪ die "ssh: $!";
72
73 while (<READER>) {
74 chomp();
75 print "$_\n";
76 }
77
78 close(READER);
79 close(WRITER);
80
82 Q: How do you supply a password to connect with ssh within a perl
83 script using the Net::SSH module?
84
85 A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage.
86
87 Q: My script is "leaking" ssh processes.
88
89 A: See "How do I avoid zombies on a Unix system" in perlfaq8,
90 IPC::Open2, IPC::Open3 and "waitpid" in perlfunc.
91
93 Ivan Kohler <ivan-netssh_pod@420.am>
94
95 John Harrison <japh@in-ta.net> contributed an example for the documen‐
96 tation.
97
98 Martin Langhoff <martin@cwa.co.nz> contributed the ssh_cmd command, and
99 Jeff Finucane <jeff@cmh.net> updated it and took care of the 0.04
100 release.
101
102 Anthony Awtrey <tony@awtrey.com> contributed a fix for those still
103 using OpenSSH v1.
104
106 Copyright (c) 2004 Ivan Kohler. Copyright (c) 2002 Freeside Internet
107 Services, LLC All rights reserved. This program is free software; you
108 can redistribute it and/or modify it under the same terms as Perl
109 itself.
110
112 Not OO.
113
114 Look at IPC::Session (also fsh)
115
117 For an all-perl implementation that does not require the system ssh
118 command, see Net::SSH::Perl instead.
119
120 ssh-keygen(1), ssh(1), IO::File, IPC::Open2, IPC::Open3
121
122
123
124perl v5.8.8 2004-02-12 SSH(3)