Readers: 4
4 entries, 1 page |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use warnings;
use strict;
use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new("A.B.C.D",
port => "22",
debug => "1",
interactive => "0",
options => [
"BatchMode 1"
]
);
$ssh->login('user','password');
my($out,$err,$exit) = $ssh->cmd("uname -a");
print "$out\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
machine: Reading configuration data /home/admin/.ssh/config
machine: Reading configuration data /etc/ssh_config
machine: Connecting to A.B.C.D, port 22.
machine: Remote protocol version 2.0, remote software version OpenSSH_4.2p1 Debian-5
machine: Net::SSH::Perl Version 1.29, protocol version 2.0.
machine: No compat match: OpenSSH_4.2p1 Debian-5.
machine: Connection established.
machine: Sent key-exchange init (KEXINIT), wait response.
machine: Algorithms, c->s: 3des-cbc hmac-sha1 none
machine: Algorithms, s->c: 3des-cbc hmac-sha1 none
machine: Entering Diffie-Hellman Group 1 key exchange.
machine: Sent DH public key, waiting for reply.
machine: Received host key, type 'ssh-dss'.
machine: Host 'A.B.C.D' is known and matches the host key.
machine: Computing shared secret key.
machine: Verifying server signature.
machine: Waiting for NEWKEYS message.
machine: Enabling incoming encryption/MAC/compression.
machine: Send NEWKEYS, enable outgoing encryption/MAC/compression.
machine: Sending request for user-authentication service.
machine: Service accepted: ssh-userauth.
machine: Trying empty user-authentication request.
machine: Authentication methods that can continue: publickey,keyboard-interactive.
machine: Next method to try is publickey.
Permission denied at ./perlssh line 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
# caution: this script logs into remote machine and execute commands.
# for the script to work fine, the sshd on the remote machine must accept
# password-based authentication. this is controlled with the parameter
# "PasswordAuthentication yes" in sshd_config.
use warnings;
use strict;
use Net::SSH::Perl;
my $host = '192.168.100.21';
my $port = '22';
my $user = 'dummy';
my $pass = 'dummy';
my %config = (
port => $port,
debug => 1,
interactive => 0,
options => ["ChallengeResponseAuthentication no"]
);
my $ssh = Net::SSH::Perl->new($host, %config);
$ssh->login($user, $pass);
my ($out, $err, $exit) = $ssh->cmd("uname -a");
print "$out\n";
if ($out =~ /^Darwin/) {
($out, $err, $exit) = $ssh->cmd("sw_vers");
print "$out\n";
}
4 entries, 1 page |