1SSH(3)                User Contributed Perl Documentation               SSH(3)
2
3
4

NAME

6       Net::SSH - Perl extension for secure shell
7

SYNOPSIS

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

DESCRIPTION

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

SUBROUTINES

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
40           confirm, 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

EXAMPLE

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

FREQUENTLY ASKED QUESTIONS

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 (at least not with this module).  Use RSA or DSA keys.
86       See the
87          quick help in the next section and the ssh-keygen(1) manpage.
88
89       A #2: See Net::SSH::Expect instead.
90
91       Q: My script is "leaking" ssh processes.
92
93       A: See "How do I avoid zombies on a Unix system" in perlfaq8,
94       IPC::Open2, IPC::Open3 and "waitpid" in perlfunc.
95

GENERATING AND USING SSH KEYS

97       1 Generate keys
98           Type:
99
100              ssh-keygen -t rsa
101
102           And do not enter a passphrase unless you wanted to be prompted for
103           one during file copying.
104
105           Here is what you will see:
106
107              $ ssh-keygen -t rsa
108              Generating public/private rsa key pair.
109              Enter file in which to save the key (/home/User/.ssh/id_rsa):
110              Enter passphrase (empty for no passphrase):
111
112              Enter same passphrase again:
113
114              Your identification has been saved in /home/User/.ssh/id_rsa.
115              Your public key has been saved in /home/User/.ssh/id_rsa.pub.
116              The key fingerprint is:
117              5a:cd:2b:0a:cd:d9:15:85:26:79:40:0c:55:2a:f4:23 User@JEFF-CPU
118
119       2 Copy public to machines you want to upload to
120           "id_rsa.pub" is your public key. Copy it to "~/.ssh" on target
121           machine.
122
123           Put a copy of the public key file on each machine you want to log
124           into.  Name the copy "authorized_keys" (some implementations name
125           this file "authorized_keys2")
126
127           Then type:
128
129                chmod 600 authorized_keys
130
131           Then make sure your home dir on the remote machine is not group or
132           world writeable.
133

AUTHORS

135       Ivan Kohler <ivan-netssh_pod@420.am>
136
137       Assistance wanted - this module could really use a maintainer with
138       enough time to at least review and apply more patches.  Or the module
139       should just be deprecated in favor of Net::SSH::Expect or made into an
140       ::Any style compatibility wrapper that uses whatver implementation is
141       avaialble (Net::SSH2, Net::SSH::Perl or shelling out like the module
142       does now).  Please email Ivan if you are interested in helping.
143
144       John Harrison <japh@in-ta.net> contributed an example for the
145       documentation.
146
147       Martin Langhoff <martin@cwa.co.nz> contributed the ssh_cmd command, and
148       Jeff Finucane <jeff@cmh.net> updated it and took care of the 0.04
149       release.
150
151       Anthony Awtrey <tony@awtrey.com> contributed a fix for those still
152       using OpenSSH v1.
153
154       Thanks to terrence brannon <tbone@directsynergy.com> for the
155       documentation in the GENERATING AND USING SSH KEYS section.
156
158       Copyright (c) 2004 Ivan Kohler.  Copyright (c) 2007-2008 Freeside
159       Internet Services, Inc.  All rights reserved.  This program is free
160       software; you can redistribute it and/or modify it under the same terms
161       as Perl itself.
162

BUGS

164       Not OO.
165
166       Look at IPC::Session (also fsh, well now the native SSH "master mode"
167       stuff)
168

SEE ALSO

170       For a perl implementation that does not require the system ssh command,
171       see Net::SSH::Perl instead.
172
173       For a wrapper version that allows you to use passwords, see
174       Net::SSH::Expect instead.
175
176       For another non-forking version that uses the libssh2 library, see
177       Net::SSH2.
178
179       For a way to execute remote Perl code over an ssh connection see
180       IPC::PerlSSH.
181
182       ssh-keygen(1), ssh(1), IO::File, IPC::Open2, IPC::Open3
183
184
185
186perl v5.34.0                      2022-01-21                            SSH(3)
Impressum