Posted on 2005-09-07 18:27:23-07 by feckusine
When using RSA keys, it's taking way too long to exchange,execute...
When I supply $password within the script it works perfectly. When I setup RSA keys on the host and turn on debug mode, it lags when it reaches:
"box: Algorithms, s->c: 3des-cbc hmac-sha1 none"
for about 60 seconds, then it lags again when it reaches:
"box: Computing shared secret key."
for roughly another 45 seconds...
Here's my debug output:
[mysql@box admin]$ time ./ssh.pl box: Reading configuration data /home/mysql/.ssh/config box: Reading configuration data /etc/ssh_config box: Connecting to sat-appprod0, port 22. box: Remote protocol version 1.99, remote software version OpenSSH_3.1p1 box: Net::SSH::Perl Version 1.28, protocol version 2.0. box: No compat match: OpenSSH_3.1p1. box: Connection established. box: Sent key-exchange init (KEXINIT), wait response. box: Algorithms, c->s: 3des-cbc hmac-sha1 none box: Algorithms, s->c: 3des-cbc hmac-sha1 none box: Entering Diffie-Hellman Group 1 key exchange. box: Sent DH public key, waiting for reply. box: Received host key, type 'ssh-dss'. box: Host 'remotebox' is known and matches the host key. box: Computing shared secret key. box: Verifying server signature. box: Waiting for NEWKEYS message. box: Enabling incoming encryption/MAC/compression. box: Send NEWKEYS, enable outgoing encryption/MAC/compression. box: Sending request for user-authentication service. box: Service accepted: ssh-userauth. box: Trying empty user-authentication request. box: Authentication methods that can continue: publickey,password,keyboard-interactive. box: Next method to try is publickey. box: Trying pubkey authentication with key file '/home/mysql/.ssh/id_rsa' box: Login completed, opening dummy shell channel. box: channel 0: new [client-session] box: Requesting channel_open for channel 0. box: channel 0: open confirm rwindow 0 rmax 32768 box: Got channel open confirmation, requesting shell. box: Requesting service shell on channel 0. box: channel 1: new [client-session] box: Requesting channel_open for channel 1. box: Entering interactive session. box: Sending command: w box: Requesting service exec on channel 1. box: channel 1: open confirm rwindow 0 rmax 32768 box: channel 1: rcvd eof box: channel 1: output open -> drain box: input_channel_request: rtype exit-status reply 0 box: channel 1: rcvd close box: channel 1: input open -> closed box: channel 1: close_read box: channel 1: obuf empty box: channel 1: output drain -> closed box: channel 1: close_write box: channel 1: send close box: channel 1: full closed 1:08pm up 29 days, 19:55, 1 users, load average: 0.46, 0.54, 0.61 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT someuser pts/2 - 8:47am 2:23m 0.05s 0.05s -bash real 1m59.037s user 1m1.360s sys 0m0.050s [mysql@box admin]$
Here's the script I'm executing:
#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use bytes; my $host = "remotebox"; my $user = "someuser"; my $cmd = "w\n"; my $ssh = Net::SSH::Perl->new($host, debug=>1, protocol=>'2,1', options=>[ "IdentityFile ~/.ssh/id_rsa", "UserKnownHostsFile ~/.ssh/known_hosts"] ); $ssh->login($user); my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print "$stdout" if($stdout); print "$stderr" if($stderr); print "$exit" if($exit);


I've been trying to debug this for 3 days now, any help would be greatly appreciated... I would use Net::SSH or Expect but they don't support STDERR like this module does.
Direct Responses: 990 | 1159 | 4806 | Write a response
Posted on 2005-09-15 10:04:02-07 by robverduijn in response to 967
Re: When using RSA keys, it's taking way too long to exchange,execute...
Hi there, I've got exactly the same problem, I thought I might have screwed up my system so I tested it on a clean install of suse9.3 ,
reinstalled all the modules and got exactly the same problem.
I did notice however that installing the Crypt::DH module took forever (it was stuck in the testing part of the cpan install for at least 20 minutes),
could it be that that module is the source of this problem?
Regards
Rob
Direct Responses: 992 | Write a response
Posted on 2005-09-15 15:27:22-07 by feckusine in response to 990
Re: When using RSA keys, it's taking way too long to exchange,execute...
You won't find a solution to this, it has to do with either the Net::SSH::Perl or The RSA/DSA code being too bloated. The package seems to generate new keys for the connections and transmission rather than using the /root/.ssh/identity files, etc which may be the cause for the lag. A good alernative is using the Net::SSH wrapper module with Expect. Only draw back with this is you can't seperate STDOUT from STDERR unless you do some file descriptor trickery, which I had to do myself. An example would be like:
sub std($){ my $ret = qq/exec 3>&1; $_[0] 2>&1 >&3 3>&-|awk '{ print "STDERR:" \$0 }'; exec 3>&-/; return($ret); }
Then do something like:
my ($cmd) = std("ls foobar");
That will prepend a "STDERR:" tag to all STDERR output that's received through the STDOUT, in which case you can regex more easily. Net::SSH and Expect is a great alternative and much much more faster. Here's a example that should get you started.
sshopen2("$username\@$host", *READER, *WRITER, "bash") || die "ssh: $!"; my $exp = Expect->exp_init(\*READER); select((select(READER), $| = 1)[0]); $| = 1, select $_ for select READER;
Then just write your commands to the WRITER fd:
print WRITER std("some command") . "\n";
You can flush the READER fd after every command has been parsed so that the next command will parse correctly, like so:
$exp->clear_accum();
Then you can write/read from the fds again with ease. Dirty hack but it works, just make sure your innitial sshopen2() uses bash as the command so you won't be opening up a new connection every time you send a command (again another dirty hack). :)
Direct Responses: Write a response
Posted on 2005-10-12 23:40:47-07 by drfunk in response to 967
Re: When using RSA keys, it's taking way too long to exchange,execute...
Try installing IO::Handle then Math::BigInt::GMP that fixed it for me..
Direct Responses: Write a response
Posted on 2007-04-10 21:18:44-07 by cormander in response to 967
Re: When using RSA keys, it's taking way too long to exchange,execute...
I had this problem as well. To fix it, I installed these perl modules: Class::ErrorHandler Math::BigInt::GMP The first one was needed by the RSA key auth module, the second one it uses to do the calculations a LOT faster. Hope this helps.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.