Hi

I'm trying to work out if it possible to use perl to solve a problem I have

We use an authentication method which involves running ssh as one user and then using powerbroker once on the remote node to access a further user. e.g.
ssh myuser@myremotenode.com enter password here pbrun mygroup myremoteuser=ksh enter password here Access granted
What I'd like to be able to do is to have a perl wrapper provide the password at each step and end up with an interactive shell on the remote host. Note the use of ssh keys is disallowed.

I've taken a look at various perl modules to do this like Net::SSH::Expect and Net::OpenSSH but can't seem to get them to do what I'm looking for.

e.g. this code gets me access to the remote host by providing the answres to the prompts but won't leave me in an interactive shell (as though I was in a ksh)

use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "remotehost.com", password=> 'mypass', user => 'user1', raw_pty => 1 ); # logon to the SSH server using those credentials. my $login_output = $ssh->login(); if ($login_output !~ /Last login/) { die "Login has failed. Login output was $login_output"; } $ssh->exec("stty raw -echo"); $ssh->send("pbrun mypbgroup user2=ksh"); $ssh->waitfor('Password:\s*\z', 3) or die "prompt 'Password' not found + after 1 second"; $ssh->send("mypass"); $ssh->waitfor('user2_prompt', 3) or die "prompt 'user2_prompt' + not found"; my $cmd1 = $ssh->exec('ls -l'); print ($cmd1); my $cmd2 = $ssh->exec('whoami'); print ($cmd2);
This allows me to connect via powerbroker as user2 on the remote host but I can only run a pre-determined set of commands.

Using expect seemed like a reasonable idea to provide seamless entry

How can I change this so that it accepts any command as if I was logged into a shell interactively ? Is that possible ?

Thanks in advance


In reply to Interactive conectin via SSH and Powerbroker by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.