Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSH::NET::PERL - works but hangs for 5 minutes

Status
Not open for further replies.

fatcoder

Technical User
Jan 26, 2009
4
CA
Hi Everyone,

I've been trying to figure out why my script hangs for 3-4 minutes prior to executing the command remotely. I know it's related to key authentication since I do not have these issues when using a username\password. I've searched for 2 days and still can't find my solution.

I just started programming so please don't flame me if I say something stupid.

Here's the code that works without a hitch:
#!/usr/bin/perl
use strict;
use Net::SSH::perl;

my $ssh = Net::SSH::perl->new('172.16.10.220',debug => 1, protocol => '2,1');
$ssh->login('monitor','12345');
my ($stdout, $stderr, $exit) = $ssh->cmd('pwd');
print $stdout . "\n";
print $stderr . "\n";
print $exit . "\n";

I then created SSH keys and confirmed that I can connect without passwords from the CLI. When taking the next step, it works however it stay stuck for 3-4 minutes before executing. Here's the script:
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH::perl;

my $host = "172.16.11.220";
my $user = "monitor";
my $cmd = "mkdir working";
my $ssh = Net::SSH::perl->new($host, debug => 1, identity_files => ["/root/.ssh/id_rsa"], protocol=>'2,1');
$ssh->login($user);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

print "$stdout";
print "$stderr";
print "$exit";

Here's the logs:

# perl Test2.pl
Reading configuration data /root/.ssh/config
Reading configuration data /etc/ssh_config
Allocated local port 1023.
Connecting to 172.16.11.63, port 22.
Remote protocol version 2.0, remote software version OpenSSH_4.3
Net::SSH::perl Version 1.33, protocol version 2.0.
No compat match: OpenSSH_4.3.
Connection established.
Sent key-exchange init (KEXINIT), wait response.
Algorithms, c->s: 3des-cbc hmac-sha1 none
Algorithms, s->c: 3des-cbc hmac-sha1 none
Entering Diffie-Hellman Group 1 key exchange.
Sent DH public key, waiting for reply.
Received host key, type 'ssh-dss'.
Host '172.16.11.220' is known and matches the host key.
Computing shared secret key.
Verifying server signature.
Waiting for NEWKEYS message.
Enabling incoming encryption/MAC/compression.
Send NEWKEYS, enable outgoing encryption/MAC/compression.
Sending request for user-authentication service.
Service accepted: ssh-userauth.
Trying empty user-authentication request.
Authentication methods that can continue: publickey,password,keyboard-interactive.
Next method to try is publickey.
Trying pubkey authentication with key file '/root/.ssh/id_rsa'

**it stays stuck here for 3-4 minutes before executing...

Can anyone point me in the right direction?

Thanks
 
Forgot to add the part of the logs after it executes:

Login completed, opening dummy shell channel.
channel 0: new [client-session]
Requesting channel_open for channel 0.
channel 0: open confirm rwindow 0 rmax 32768
Got channel open confirmation, requesting shell.
Requesting service shell on channel 0.
channel 1: new [client-session]
Requesting channel_open for channel 1.
Entering interactive session.
Sending command: mkdir working
Requesting service exec on channel 1.
channel 1: open confirm rwindow 0 rmax 32768
channel 1: rcvd eof
channel 1: output open -> drain
channel 1: obuf empty
channel 1: output drain -> closed
channel 1: close_write
input_channel_request: rtype exit-status reply 0
channel 1: rcvd close
channel 1: input open -> closed
channel 1: close_read
channel 1: send close
channel 1: full closed
Use of uninitialized value in string at Test2.pl line 13.
Use of uninitialized value in string at Test2.pl line 14.
 
Thanks Mbrooks for your post. Here's the answers to your questions:

Script is being ran as root.
Permission on id_rsa was 640, changed it to 600

The script work but hangs for a couple of minutes before authenticating. Should I be using something else? Do I need to reference a different module for authentication?
 
Has anyone gotten keys to work without it hanging? If so, would you be kind enough to post your script?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top