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

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

Replies are listed 'Best First'.
Re: Switch to different user using Net::SSH2 perl module
by moritz (Cardinal) on Jun 18, 2008 at 18:46 UTC
    You can either use expect, or sudo for a password-less user change.
      As we are using Net::SSH2 perl module for connecting to remote system, can any one suggest how can we integrate Expect and Net::SSH2

      Sushil Kumar