Respected Perl Monks,

I was using Net::SSH2 perl module for connecting to remote system and executing fews command there.

With the new requirement in the project, we had to switch user using su command to a previllaged user and execute few privileaged commands there.

We are connected to remote system using normal user with Net::SSH2 function and here is the below code

my $ssh2 = Net::SSH2->new(); eval {$ssh2->connect($rip) ; }; if( $@ ) {print qq{ Error: Cannot connect to $rip : SSH service Failed +}; exit 1; } return "Error: Authenticate fail for $rip" unless $ssh2->auth( +username => $rusr,password=>$rpwd); $chan2 = $ssh2->channel; die "Can not create a shell on channel " unless $chan2->shell; die "Can not set blocking field " unless $chan2->blocking(0); $chan2->ext_data('merge'); $ssh2->auth(username => $rusr,password=>$rpwd);
But after we connect using a normal user and try to switch to a privileged user for which the below is the continued code
print $chan2 "su $user2 \n"; print $chan2 "$pass2 \n";
when we execute this script it is giving the following output:

<code> standard in must be a tty </code

Can any one suggest me how to integrate this switching of user using Net::SSH2

Thanks in advance,

Work Hard Party Harderrr!!
Sushil Kumar

In reply to Switch to different user using Net::SSH2 perl module by msk_0984

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.