Net::SSH::Perl

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Net::SSH::Perl

    Hi all,

    I am currently using Net::SSH::Perl module to login in my remote machine.
    Below is my code:

    ==================================
    #!/usr/bin/perl

    use Net::SSH::Perl;

    $user="jaws";
    $pass="password";
    $host="111.222.333.444";

    my $ssh = Net::SSH::Perl->new($host,"'1,2'");
    $ssh->login($user, $pass);
    $ssh->cmd("my_command");
    ==================================

    the output of the last line requires me to input username and password. How
    can do it using this module? I've tried to search in the manual of the
    package but i didn't find one to answer my question and even in the web so i
    decided to ask help from you.

    Thanks.

    jaws

    ---------------
    Computer system security is a journey, not a destination.



    Jaws Guest

  2. Similar Questions and Discussions

    1. Off Topic: Active Perl Native Windows / cygwin perl
      I have both activestate windows native perl installed and the default cygwin perl. How can I have the cygwin shell use the windows perl rather...
    2. Control a non-perl image viewer from perl script
      Below is a (non-finished) script that trys to run a linux viewer called eog (eye of gnome) in a script that will eventually allow me to power thru...
    3. Re : Installing CPAN Perl Modules with Activestate Perl 5. v5.8
      Hi, In the process of trying to get perl modules installed, I downloaded over 300 Activestate specific perl modules and they work fine (of the ones...
    4. Effeciency question - perl scripts v's perl exe's
      Max Adams wrote: The only existing Perl compiler is part of perl. Anything else is just a packager that puts a perl, required modules, and the...
    5. Designing Interfaces with Perl and Perl APIs
      Hi, I am a long date perl programmer, and from time to time, I am having the same trouble: - To design interfaces for a self contained...
  3. #2

    Default Re: Net::SSH::Perl

    On Wed, 3 Sep 2003 12:54:07 +0800, [email]jaws@skyinet.net[/email] (Jaws) wrote:
    >Hi all,
    >
    >I am currently using Net::SSH::Perl module to login in my remote machine.
    >Below is my code:
    >
    >==================================
    >#!/usr/bin/perl
    >
    >use Net::SSH::Perl;
    >
    >$user="jaws";
    >$pass="password";
    >$host="111.222.333.444";
    >
    >my $ssh = Net::SSH::Perl->new($host,"'1,2'");
    >$ssh->login($user, $pass);
    >$ssh->cmd("my_command");
    >==================================
    >
    >the output of the last line requires me to input username and password. How
    >can do it using this module? I've tried to search in the manual of the
    >package but i didn't find one to answer my question and even in the web so i
    >decided to ask help from you.
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Net::SSH::Perl;

    my $user = "zz";
    my $password = "ztest";
    my @hosts = qw(localhost zentara.zentara.net);

    foreach my $host (@hosts){
    my $cmd = "/usr/bin/uptime";
    my $ssh = Net::SSH::Perl->new( $host, port => 22 ,debug => 1);
    $ssh->login($user,$password);

    my($out) = $ssh->cmd($cmd);
    my ($time,$uptime) = (split /\s+/,$out)[1,3];
    chop $uptime;
    print "$out\n";
    print "$host has been up $uptime\n";
    }




    Zentara Guest

  4. #3

    Default Re: Net::SSH::Perl


    ------------------------------------------------
    On Thu, 04 Sep 2003 14:23:44 -0400, zentara <zentara@highstream.net> wrote:
    > On Wed, 3 Sep 2003 12:54:07 +0800, [email]jaws@skyinet.net[/email] (Jaws) wrote:
    >
    > >Hi all,
    > >
    > >I am currently using Net::SSH::Perl module to login in my remote machine.
    > >Below is my code:
    > >
    > >==================================
    > >#!/usr/bin/perl
    > >
    > >use Net::SSH::Perl;
    > >
    > >$user="jaws";
    > >$pass="password";
    > >$host="111.222.333.444";
    > >
    > >my $ssh = Net::SSH::Perl->new($host,"'1,2'");
    > >$ssh->login($user, $pass);
    > >$ssh->cmd("my_command");
    > >==================================
    > >
    > >the output of the last line requires me to input username and password. How
    > >can do it using this module? I've tried to search in the manual of the
    > >package but i didn't find one to answer my question and even in the web so i
    > >decided to ask help from you.
    >
    > #!/usr/bin/perl
    > use strict;
    > use warnings;
    > use Net::SSH::Perl;
    >
    > my $user = "zz";
    > my $password = "ztest";
    > my @hosts = qw(localhost zentara.zentara.net);
    >
    > foreach my $host (@hosts){
    > my $cmd = "/usr/bin/uptime";
    > my $ssh = Net::SSH::Perl->new( $host, port => 22 ,debug => 1);
    > $ssh->login($user,$password);
    >
    > my($out) = $ssh->cmd($cmd);
    > my ($time,$uptime) = (split /\s+/,$out)[1,3];
    > chop $uptime;
    > print "$out\n";
    > print "$host has been up $uptime\n";
    > }
    Not sure that got to the OPs question unless you have a really weird uptime command that expects input. To me the best option is to put a script out on the remote host that handles the local inputs/outputs and then switch your 'cmd' call to call that script rather than the program directly.

    If that is not possible and the command is expecting its input on STDIN and you don't need to worry about what the prompt was then you should check the docs again, in particular:

    "($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])

    If $stdin is provided, it's supplied to the remote command $cmd on standard input."

    If you really need to work with an interactive interface you will probably have to massage the underlying socket/buffer/packets, etc. or you might be able to do something with the 'shell' method attached to some local filehandles that handle the interactive component for you, but yikes.

    Though I don't usually suggest it you might consider the 'Expect' module and calling 'ssh' on the command line.

    [url]http://danconia.org[/url]
    wiggins@danconia.org Guest

  5. #4

    Default Re: Net::SSH::Perl

    In comp.lang.perl.misc blob <jaws@skyinet.net> wrote:
    b>Hi all,
    b>
    b>Below is my script that will be used to connect to a remote host and
    b>change my password automatically:
    b>
    b>===========================================
    b>#!/usr/bin/perl
    b>
    b>
    b>use strict();
    b>use Net::SSH::Perl;
    b>
    <snipped>
    b>Does anybody has an idea what's missing or wrong with my script?
    b>

    I didn't know strict was functions?

    chesucat

    --
    [email]chesucat@sdf.lonestar.org[/email]
    no fortune!:-(


    chesucat@freeshell.org Guest

  6. #5

    Default Re: Net::SSH::Perl

    Sorry, I cant comment on the perl as yet but, are you not in the least bit
    worried that someone might hack into your base system - get the unencrypted
    password (old password) then log on - using ssh to the other box ?

    ssh is not 100% flawless

    From a security point of view it is a nightmare, from a SA point of view - I
    can see where you are coming from !

    Just curious is all
    "blob" <jaws@skyinet.net> wrote in message news:3f57f2ae@news.skyinet.net...
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::Perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws
    >

    get-fuzzy Guest

  7. #6

    Default Re: Net::SSH::Perl

    Sorry, I cant comment on the perl as yet but, are you not in the least bit
    worried that someone might hack into your base system - get the unencrypted
    password (old password) then log on - using ssh to the other box ?

    ssh is not 100% flawless

    From a security point of view it is a nightmare, from a SA point of view - I
    can see where you are coming from !

    Just curious is all
    "blob" <jaws@skyinet.net> wrote in message news:3f57f2ae@news.skyinet.net...
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::Perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws
    >

    get-fuzzy Guest

  8. #7

    Default Re: Net::SSH::Perl

    <chesucat@freeshell.org> wrote in comp.lang.perl.misc:
    > In comp.lang.perl.misc blob <jaws@skyinet.net> wrote:
    > b>Hi all,
    > b>
    > b>Below is my script that will be used to connect to a remote host and
    > b>change my password automatically:
    > b>
    > b>===========================================
    > b>#!/usr/bin/perl
    > b>
    > b>
    > b>use strict();
    > b>use Net::SSH::Perl;
    > b>
    > <snipped>
    > b>Does anybody has an idea what's missing or wrong with my script?
    > b>
    >
    > I didn't know strict was functions?
    It is not, but the call "use strict()" doesn't have any effect.

    The part in "()" is interpreted as an import list to the strict pragma
    (which is technically a module). Since it is empty, strict's import
    function isn't called, and no strictures are activated.

    This is unlikely to be the cause of the OPs problem, but it doesn't
    bode well for the rest of the code.

    Anno
    Anno Siegel Guest

  9. #8

    Default Net::SSH::Perl

    Hi all,

    Below is my script that will be used to connect to a remote host and
    change my password automatically:

    ===========================================
    #!/usr/bin/perl


    use strict();
    use Net::SSH::Perl;


    $user="jaws";
    $pass="password";
    $host="xxx.xxx.xxx.xxx";
    $old_password="password";
    $new_password="newpass";


    my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    $ssh->login($user, $pass);


    $ssh->register_handler("stderr", sub {
    my($channel, $buffer) = @_;
    my $str = $buffer->bytes;


    if ($str eq "Enter login password: ") {
    $channel->send_data($old_password);
    }


    elsif ($str eq "New password: ") {
    $channel->send_data($new_password);
    }

    elsif ($str eq "Re-enter new password: ") {
    $channel->send_data($new_password);
    }
    });
    $ssh->cmd('passwd');
    ==========================================

    After running the program, my password didnt changed I was still able to
    connect using the old password.

    Does anybody has an idea what's missing or wrong with my script?

    Thanks.

    Jaws

    blob Guest

  10. #9

    Default Net::SSH::Perl

    Hi all,

    Below is my script that will be used to connect to a remote host and
    change my password automatically:

    ===========================================
    #!/usr/bin/perl


    use strict();
    use Net::SSH::Perl;


    $user="jaws";
    $pass="password";
    $host="xxx.xxx.xxx.xxx";
    $old_password="password";
    $new_password="newpass";


    my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    $ssh->login($user, $pass);


    $ssh->register_handler("stderr", sub {
    my($channel, $buffer) = @_;
    my $str = $buffer->bytes;


    if ($str eq "Enter login password: ") {
    $channel->send_data($old_password);
    }


    elsif ($str eq "New password: ") {
    $channel->send_data($new_password);
    }

    elsif ($str eq "Re-enter new password: ") {
    $channel->send_data($new_password);
    }
    });
    $ssh->cmd('passwd');
    ==========================================

    After running the program, my password didnt changed I was still able to
    connect using the old password.

    Does anybody has an idea what's missing or wrong with my script?

    Thanks.

    Jaws

    blob Guest

  11. #10

    Default Re: Net::SSH::Perl

    On Fri, 05 Sep 2003 10:07:49 -0800
    blob <jaws@skyinet.net> wrote:
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    >
    > change my password automatically:
    <sniped for brevity>
    >
    > After running the program, my password didnt changed I was still
    > able to connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    Just a suggestion - you may wish to use one of the Expect modules for
    what you're doing. Expect is, IMHO, better suited for this task. And
    in true Perl fashion, there is a module to interact with Expect :)

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    for more information.

    a fortune quote ...
    Hlade's Law: If you have a difficult task, give it to a lazy
    person -- they will find an easier way to do it.
    James Willmore Guest

  12. #11

    Default Re: Net::SSH::Perl

    On Fri, 05 Sep 2003 10:07:49 -0800
    blob <jaws@skyinet.net> wrote:
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    >
    > change my password automatically:
    <sniped for brevity>
    >
    > After running the program, my password didnt changed I was still
    > able to connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    Just a suggestion - you may wish to use one of the Expect modules for
    what you're doing. Expect is, IMHO, better suited for this task. And
    in true Perl fashion, there is a module to interact with Expect :)

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    for more information.

    a fortune quote ...
    Hlade's Law: If you have a difficult task, give it to a lazy
    person -- they will find an easier way to do it.
    James Willmore Guest

  13. #12

    Default Re: Net::SSH::Perl

    On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::Perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws
    Instead of waiting for the exact string, why not use regular expresions,
    which might eliminate typo's. Something like:

    if ($str =~ /enter\s+login\s+password/i ) {
    $channel->send_data($old_password);
    }


    elsif ($str =~ /new\s+password/i ) {
    $channel->send_data($new_password);
    }

    elsif ($str =~ /re.enter\s+new\s+password/i ) {
    $channel->send_data($new_password);
    }

    Cheers

    --
    Nico Coetzee

    [url]http://www.itfirms.co.za/[/url]
    [url]http://za.pm.org/[/url]
    [url]http://forums.databasejournal.com/[/url]

    To the systems programmer, users and applications serve only to provide a
    test load.

    Nico Coetzee Guest

  14. #13

    Default Re: Net::SSH::Perl

    On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::Perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws
    Instead of waiting for the exact string, why not use regular expresions,
    which might eliminate typo's. Something like:

    if ($str =~ /enter\s+login\s+password/i ) {
    $channel->send_data($old_password);
    }


    elsif ($str =~ /new\s+password/i ) {
    $channel->send_data($new_password);
    }

    elsif ($str =~ /re.enter\s+new\s+password/i ) {
    $channel->send_data($new_password);
    }

    Cheers

    --
    Nico Coetzee

    [url]http://www.itfirms.co.za/[/url]
    [url]http://za.pm.org/[/url]
    [url]http://forums.databasejournal.com/[/url]

    To the systems programmer, users and applications serve only to provide a
    test load.

    Nico Coetzee Guest

  15. #14

    Default Net::SSH::Perl


    Hi All,

    I remember i read somewhere about some limitations of Net::SSH::Perl on
    windows systems particularly something about 5.8
    but can't find the link now.

    Can anybody point me to it without much effort.??


    Thanx,
    -Sharad
    Sharad Gupta Guest

  16. #15

    Default Net::SSH::Perl

    Hi,

    i have a problem with the Net::SSH::Perl module. i'd like to code a ssh
    client in perl, that needs no special functions. it only has to login
    and stay there until disconnection. after that it should reconnect and
    so on...
    i won't enter any commands at the shell after login...it just has to
    login and finito.

    but:
    with the perl ssh module it connects to the given server, but the login
    process does not work, i always get a connection timeout.

    where is my fault?

    ---
    loginperl.pl

    #!/usr/bin/perl
    use Net::SSH::Perl;

    my $host = 'my.nice.host';
    my $user = 'username';
    my $passwd = 'password';

    my $ssh = Net::SSH::Perl->new($host, protocol => 2, debug => true);
    $ssh->login($user,$passwd);


    thx,

    martin
    Martin Sommer Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139