Problem connecting through ssh with Net:::Telnet

From: ChrisG (bombpop_at_comcast.net)
Date: 04/24/04

  • Next message: Steven N. Hirsch: "Re: [Slightly OT] Free version of MSFT VC++ now available"
    Date: 23 Apr 2004 15:42:29 -0700
    
    

    I'm not able to get this example script from the Net::Telnet CPAN
    (http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm#EXAMPLES)
    page to work. From what I can tell I never receive a password prompt.
     It looks like the first line I read in is "Permission denied, please
    try again.".
    Here are the results from input_log():

    Permission denied, please try again.
    Permission denied, please try again.
    Permission denied (publickey,password,keyboard-interactive).

    Here are the results from dump_log():

    < 0x00000: 50 65 72 6d 69 73 73 69 6f 6e 20 64 65 6e 69 65
    Permission denie
    < 0x00010: 64 2c 20 70 6c 65 61 73 65 20 74 72 79 20 61 67 d.
    please try ag
    < 0x00020: 61 69 6e 2e 0d 0d 0a ain....

    < 0x00000: 50 65 72 6d 69 73 73 69 6f 6e 20 64 65 6e 69 65
    Permission denie
    < 0x00010: 64 2c 20 70 6c 65 61 73 65 20 74 72 79 20 61 67 d.
    please try ag
    < 0x00020: 61 69 6e 2e 0d 0d 0a ain....

    < 0x00000: 50 65 72 6d 69 73 73 69 6f 6e 20 64 65 6e 69 65
    Permission denie
    < 0x00010: 64 20 28 70 75 62 6c 69 63 6b 65 79 2c 70 61 73 d
    (publickey.pas
    < 0x00020: 73 77 6f 72 64 2c 6b 65 79 62 6f 61 72 64 2d 69
    sword.keyboard-i
    < 0x00030: 6e 74 65 72 61 63 74 69 76 65 29 2e 0d 0d 0a
    nteractive)....

    I am able to shh to this machine manually with no problems. If I use
    RSA keys, I am able to connect to the machine and everything works
    perfectly. It is just the login portion that is not working.

    Any ideas on what the problem could be? Thanks.
     

    #!/usr/bin/perl

        ## Main program.
        {
            my ($pty, $ssh, @lines);
            my $host = "localhost";
            my $user = "###";
            my $password = "###";
            my $prompt = '/[\$%#>] $/';

            ## Start ssh program.
            $pty = &spawn("ssh", "-l", $user, $host); # spawn() defined
    below

            ## Create a Net::Telnet object to perform I/O on ssh's tty.
            use Net::Telnet;
            $ssh = new Net::Telnet (-fhopen => $pty,
                                    -prompt => $prompt,
                                    -telnetmode => 0,
                                    -cmd_remove_mode => 1,
                                    -output_record_separator => "\r");

            $ssh->input_log('passwd.log');
            $ssh->dump_log('dump.log');

            $line = $ssh->getline(); <--produces "Permission denied,
    please try again."
            print "line=$line\n";
            ## Login to remote host.
            $ssh->waitfor(-match => '/password: ?$/i',
                          -errmode => "return")
                or die "problem connecting to host: ", $ssh->lastline;
            $ssh->print($password);
            $ssh->waitfor(-match => $ssh->prompt,
                          -errmode => "return")
                or die "login failed: ", $ssh->lastline;

            ## Send command, get and print its output.
            @lines = $ssh->cmd("who");
            print @lines;

            exit;
        } # end main program

        sub spawn {
            my(@cmd) = @_;
            my($pid, $pty, $tty, $tty_fd);

            ## Create a new pseudo terminal.
            use IO::Pty ();
            $pty = new IO::Pty
                or die $!;

            ## Execute the program in another process.
            unless ($pid = fork) { # child process
                die "problem spawning program: $!\n" unless defined $pid;

                ## Disassociate process from existing controlling
    terminal.
                use POSIX ();
                POSIX::setsid
                    or die "setsid failed: $!";

                ## Associate process with a new controlling terminal.
                $tty = $pty->slave;
                $tty_fd = $tty->fileno;
                close $pty;

                ## Make stdio use the new controlling terminal.
                open STDIN, "<&$tty_fd" or die $!;
                open STDOUT, ">&$tty_fd" or die $!;
                open STDERR, ">&STDOUT" or die $!;
                close $tty;

                ## Execute requested program.
                exec @cmd
                    or die "problem executing $cmd[0]\n";
            } # end child process

            $pty;
        } # end sub spawn


  • Next message: Steven N. Hirsch: "Re: [Slightly OT] Free version of MSFT VC++ now available"