Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Net::SSH::Perl returns error on pty allocation

by gdanenb (Acolyte)
on Mar 03, 2013 at 08:37 UTC ( [id://1021488]=perlquestion: print w/replies, xml ) Need Help??

gdanenb has asked for the wisdom of the Perl Monks concerning the following question:

I posted the question on another forum but did not get an answer...

The script supposed to run on my server and executing command remotely(over ssh) on a customer server.

The problem is that I don't have exactly the same platform as a customer OS to test connectivity over ssh. It works on my test servers fine but when working in front of customer server it exits with following:

"Received disconnect message: No pty allocated, pty required with Telnet SSH at /usr/cti/apps/CSPbase/Perl/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 300"

When executing ssh on command line in front of this server, its working...

$ssh = Net::SSH::Perl->new($ip); $ssh->login($remoteUser, $remotePass) ; ($stdout, $stderr, $exit) = $ssh->cmd($cmd);

what could be an issue here?

Replies are listed 'Best First'.
Re: Net::SSH::Perl returns error on pty allocation
by Khen1950fx (Canon) on Mar 03, 2013 at 12:25 UTC

    No pty allocated, pty required..

    Use use_pty => 1 in the constructor; also, the customer server expects SSH2, so use protocol => 2 in the constructor also. Here's the way that I would do it:

    #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; my $user = 'user'; my $pass = 'password'; my $cmd = "ls /root"; my $ssh = Net::SSH::Perl->new('localhost', debug => 1, protocol => 2, use_pty => 1, ); $ssh->login($user, $pass) ; if ($cmd) { my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print $stdout if $stdout; print $stderr if $stderr; } else { eval "use Term::ReadKey;"; ReadMode('raw'); eval "END { ReadMode('restore') };"; $ssh->shell; print "Connection to host closed.\n"; } __END__

      Is there an option to send commands and collect output when using $ssh->shell interactive mode?

      I think this is the only way I'll success since customer node is not a standard Linux box

      Anyway, this is the output when I run the code above:

      sem1: Reading configuration data /root/.ssh/config sem1: Reading configuration data /etc/ssh_config sem1: Allocated local port 1023. sem1: Connecting to 1.1.1.1, port 22. sem1: Remote protocol version 2.0, remote software version OpenSSH_4.3 +-40020723001500 sem1: Net::SSH::Perl Version 1.33, protocol version 2.0. sem1: No compat match: OpenSSH_4.3-40020723001500. sem1: Connection established. sem1: Sent key-exchange init (KEXINIT), wait response. sem1: Algorithms, c->s: 3des-cbc hmac-sha1 none sem1: Algorithms, s->c: 3des-cbc hmac-sha1 none sem1: Entering Diffie-Hellman Group 1 key exchange. sem1: Sent DH public key, waiting for reply. sem1: Received host key, type 'ssh-dss'. sem1: Host '1.1.1.1' is known and matches the host key. sem1: Computing shared secret key. sem1: Verifying server signature. sem1: Waiting for NEWKEYS message. sem1: Enabling incoming encryption/MAC/compression. sem1: Send NEWKEYS, enable outgoing encryption/MAC/compression. sem1: Sending request for user-authentication service. sem1: Service accepted: ssh-userauth. sem1: Trying empty user-authentication request. sem1: Authentication methods that can continue: password. sem1: Next method to try is password. sem1: Trying password authentication. sem1: Login completed, opening dummy shell channel. sem1: channel 0: new [client-session] sem1: Requesting channel_open for channel 0. sem1: channel 0: open confirm rwindow 0 rmax 32768 sem1: Got channel open confirmation, requesting shell. sem1: Requesting service shell on channel 0. sem1: channel 1: new [client-session] sem1: Requesting channel_open for channel 1. sem1: Entering interactive session. Received disconnect message: No pty allocated, pty required with Telne +t SSH at /usr/cti/apps/CSPbase/Perl/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/S +SH2.pm line 300
        Try adding set_interactive to the constructor.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1021488]
Approved by kcott
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found