Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Question on input password on ssh prompt

Reply
Thread Tools

Question on input password on ssh prompt

 
 
Mav
Guest
Posts: n/a
 
      09-15-2007
Hi, all
I am writing a perl script running on the XP, the machine already
have openssh installed. The script would call ssh command and send a
command to the remote host.
The code like.

#my.pl
$user = "user";
$passwd = "mypasswd";
$ipaddress = "somehost";
$command = "ls -la";
..
print ("Invoke command on host : $ipaddress);
system("ssh $user\@$ipaddress $command");
#check for error message come back from the system call.
#Todo: need to input the password.
...
---end here ---

However right after I made the system call for ssh, it prompts for the
password.

c:\>perl my.pl
Invoke command on host : somehost
enter password: <--- my program stopped right here waiting.

I understood that perl provides pm packages (in this case SSH) to
get this work done, but the script I am going to run, only will get
the perl installed and perl.dll, not extra module.

My question is:
1) Is that a way I can feed it the password without install any
module?, if so, how?
2) Or where I can find out more regarding input after prompt
waiting?
3) is that a way I can get the command (in this case ls -la) return
result?

Thanks for any input,

Regards,
Mav

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      09-16-2007

Quoth Mav <(E-Mail Removed)>:
> Hi, all
> I am writing a perl script running on the XP, the machine already
> have openssh installed. The script would call ssh command and send a
> command to the remote host.
> The code like.

<snip>
>
> However right after I made the system call for ssh, it prompts for the
> password.
>
> c:\>perl my.pl
> Invoke command on host : somehost
> enter password: <--- my program stopped right here waiting.
>
> I understood that perl provides pm packages (in this case SSH) to
> get this work done, but the script I am going to run, only will get
> the perl installed and perl.dll, not extra module.


You can use PAR (from CPAN) to package a script plus all dependant
modules up into a single file that can be run with just perl installed.
It's really not worth avoiding the use of modules.

> My question is:
> 1) Is that a way I can feed it the password without install any
> module?, if so, how?


No. However, you can switch to public-key authentication, which doesn't
require you enter the password.

> 2) Or where I can find out more regarding input after prompt
> waiting?


Err... under Unix, the answer is 'use a pty'. I don't know if it is even
possible to emulate this under Win32: it depends on exactly how ssh
prompts for the password.

Ben

 
Reply With Quote
 
 
 
 
Mav
Guest
Posts: n/a
 
      09-17-2007
On Sep 16, 2:31 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Mav <(E-Mail Removed)>:
>
>
>
> > Hi, all
> > I am writing a perl script running on the XP, the machine already
> > have openssh installed. The script would call ssh command and send a
> > command to the remote host.
> > The code like.

> <snip>
>
> > However right after I made the system call for ssh, it prompts for the
> > password.

>
> > c:\>perl my.pl
> > Invoke command on host : somehost
> > enter password: <--- my program stopped right here waiting.

>
> > I understood that perl provides pm packages (in this case SSH) to
> > get this work done, but the script I am going to run, only will get
> > the perl installed and perl.dll, not extra module.

>
> You can use PAR (from CPAN) to package a script plus all dependant
> modules up into a single file that can be run with just perl installed.
> It's really not worth avoiding the use of modules.
>
> > My question is:
> > 1) Is that a way I can feed it the password without install any
> > module?, if so, how?

>
> No. However, you can switch to public-key authentication, which doesn't
> require you enter the password.
>
> > 2) Or where I can find out more regarding input after prompt
> > waiting?

>
> Err... under Unix, the answer is 'use a pty'. I don't know if it is even
> possible to emulate this under Win32: it depends on exactly how ssh
> prompts for the password.
>
> Ben


Ben, Thanks for your input. I will look into PAR. I guess when after
the system call like
system("myapp.exe"), however, if myapp.exe is prompting for input, I
don't think perl will able to feed in the input then.

> No. However, you can switch to public-key authentication, which doesn't
> require you enter the password.


In fact, The actual script I am working actually first generates the
public key on the PC side(for that PC), then append the public key
into linux (.ssh/authorized_key) entry thru ssh command. So next time,
if the PC invokes a command from the PC to linux side thru ssh, it
will not prompt the password. Any suggestion?

Thanks,
Mav


 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      09-17-2007
Mav wrote:

> In fact, The actual script I am working actually first generates the
> public key on the PC side(for that PC), then append the public key
> into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> if the PC invokes a command from the PC to linux side thru ssh, it
> will not prompt the password. Any suggestion?


You have to authenticate to have SSH work. That authentication
can be public key or by providing the password. You might want
to look at the Expect module, to automate the initial authentication
with the password. Probably the best route is if the ssh keys don't
exist, then to have the script prompt for the password when it
runs, and have it pass it to SSH, using Expect.
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      09-17-2007

Quoth "J. Gleixner" <(E-Mail Removed)>:
> Mav wrote:
>
> > In fact, The actual script I am working actually first generates the
> > public key on the PC side(for that PC), then append the public key
> > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > if the PC invokes a command from the PC to linux side thru ssh, it
> > will not prompt the password. Any suggestion?

>
> You have to authenticate to have SSH work. That authentication
> can be public key or by providing the password. You might want
> to look at the Expect module, to automate the initial authentication
> with the password. Probably the best route is if the ssh keys don't
> exist, then to have the script prompt for the password when it
> runs, and have it pass it to SSH, using Expect.


No, that won't work, as Expect requires ptys, which WinXP doesn't have.
I think the OP's best way forward is to try Net::SSH::W32Perl, which can
log in with a password.

Ben

 
Reply With Quote
 
Mav
Guest
Posts: n/a
 
      09-17-2007
On Sep 17, 10:23 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth "J. Gleixner" <(E-Mail Removed)>:
>
> > Mav wrote:

>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?

>
> > You have to authenticate to have SSH work. That authentication
> > can be public key or by providing the password. You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.

>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben


Thanks, Ben
I looks into the Net::SSH::W32Perl, when I tried to use that I got the
error:

use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);

The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
Perl.pm line
110.

line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
you encounter the same problem? That means that I have to set the
$HOME in my script?

Thanks,
Mav



 
Reply With Quote
 
Mav
Guest
Posts: n/a
 
      09-17-2007
On Sep 17, 10:23 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth "J. Gleixner" <(E-Mail Removed)>:
>
> > Mav wrote:

>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?

>
> > You have to authenticate to have SSH work. That authentication
> > can be public key or by providing the password. You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.

>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben


my code:
use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
$ssh->login('user', 'passwd');
my ($out, $err, $exit) = $ssh->cmd('ls');

However, if I set the $HOME =c:\LLL_work, my script works, however, it
hangs almost 1 hr, nothing returns. (See below)

My question:
1) Is that a bug on the module that need to set $HOME or something I
did wrong?
2) I could not figure out why it hangs? seems my ssh (I ran from
cmd.exe), I have no problem to access the Remote Debian box from the
XP. Only problem is from my script?

I have the perl on PC.
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46

== Here is what I did ===
C:\>set HOME=c:\LLL_work

C:\LLL_work>perl x.pl
D510: Reading configuration data c:\LLL_work/.ssh/config
D510: Reading configuration data /etc/ssh_config
D510: Connecting to osm-juno2.caclab.cac.cpqcorp.net, port 22.
D510: Socket created, turning on blocking...
D510: Remote version string: SSH-2.0-OpenSSH_4.3p2 Debian-9

D510: Remote protocol version 2.0, remote software version
OpenSSH_4.3p2
Debian-9
D510: Net::SSH:erl Version 1.30, protocol version 2.0.
D510: No compat match: OpenSSH_4.3p2 Debian-9.
D510: Connection established.
D510: Sent key-exchange init (KEXINIT), wait response.
D510: Algorithms, c->s: 3des-cbc hmac-sha1 none
D510: Algorithms, s->c: 3des-cbc hmac-sha1 none
D510: Entering Diffie-Hellman Group 1 key exchange.
D510: Sent DH public key, waiting for reply.
D510: Received host key, type 'ssh-dss'.
D510: Permanently added 'Myhost.machine.com' to the list o
f known hosts.
D510: Computing shared secret key.
D510: Verifying server signature.
D510: Waiting for NEWKEYS message.
D510: Enabling incoming encryption/MAC/compression.
D510: Send NEWKEYS, enable outgoing encryption/MAC/compression.
D510: Sending request for user-authentication service.
D510: Service accepted: ssh-userauth.
D510: Trying empty user-authentication request.
D510: Authentication methods that can continue: publickey,password.
D510: Next method to try is publickey.
D510: Next method to try is password.
D510: Trying password authentication.
D510: Login completed, opening dummy shell channel.
D510: channel 0: new [client-session]
D510: Requesting channel_open for channel 0.
D510: channel 0: open confirm rwindow 0 rmax 32768
D510: Got channel open confirmation, requesting shell.
D510: Requesting service shell on channel 0.
D510: channel 1: new [client-session]
D510: Requesting channel_open for channel 1.
D510: Entering interactive session.
D510: Sending command: ls
D510: Requesting service exec on channel 1.
D510: channel 1: open confirm rwindow 0 rmax 32768
D510: input_channel_request: rtype exit-status reply 0
D510: channel 1: rcvd eof
D510: channel 1: output open -> drain
D510: channel 1: rcvd close
D510: channel 1: input open -> closed
D510: channel 1: close_read <==================Hang right here.

 
Reply With Quote
 
Mav
Guest
Posts: n/a
 
      09-17-2007
On Sep 17, 10:23 am, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth "J. Gleixner" <(E-Mail Removed)>:
>
> > Mav wrote:

>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?

>
> > You have to authenticate to have SSH work. That authentication
> > can be public key or by providing the password. You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.

>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben


y code:
use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
$ssh->login('user', 'passwd');
my ($out, $err, $exit) = $ssh->cmd('ls');

However, if I set the $HOME =c:\LLL_work, my script works, however, it
hangs almost 1 hr, nothing returns. (See below)

My question:
1) Is that a bug on the module that need to set $HOME or something I
did wrong?
2) I could not figure out why it hangs? seems my ssh (I ran from
cmd.exe), I have no problem to access the Remote Debian box from the
XP. Only problem is from my script?

I have the perl on PC.
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46

== Here is what I did ===
C:\>set HOME=c:\LLL_work

C:\LLL_work>perl x.pl
D510: Reading configuration data c:\LLL_work/.ssh/config
D510: Reading configuration data /etc/ssh_config
D510: Connecting to Myhost.machine.com, port 22.
D510: Socket created, turning on blocking...
D510: Remote version string: SSH-2.0-OpenSSH_4.3p2 Debian-9

D510: Remote protocol version 2.0, remote software version
OpenSSH_4.3p2
Debian-9
D510: Net::SSH:erl Version 1.30, protocol version 2.0.
D510: No compat match: OpenSSH_4.3p2 Debian-9.
D510: Connection established.
D510: Sent key-exchange init (KEXINIT), wait response.
D510: Algorithms, c->s: 3des-cbc hmac-sha1 none
D510: Algorithms, s->c: 3des-cbc hmac-sha1 none
D510: Entering Diffie-Hellman Group 1 key exchange.
D510: Sent DH public key, waiting for reply.
D510: Received host key, type 'ssh-dss'.
D510: Permanently added 'Myhost.machine.com' to the list o
f known hosts.
D510: Computing shared secret key.
D510: Verifying server signature.
D510: Waiting for NEWKEYS message.
D510: Enabling incoming encryption/MAC/compression.
D510: Send NEWKEYS, enable outgoing encryption/MAC/compression.
D510: Sending request for user-authentication service.
D510: Service accepted: ssh-userauth.
D510: Trying empty user-authentication request.
D510: Authentication methods that can continue: publickey,password.
D510: Next method to try is publickey.
D510: Next method to try is password.
D510: Trying password authentication.
D510: Login completed, opening dummy shell channel.
D510: channel 0: new [client-session]
D510: Requesting channel_open for channel 0.
D510: channel 0: open confirm rwindow 0 rmax 32768
D510: Got channel open confirmation, requesting shell.
D510: Requesting service shell on channel 0.
D510: channel 1: new [client-session]
D510: Requesting channel_open for channel 1.
D510: Entering interactive session.
D510: Sending command: ls
D510: Requesting service exec on channel 1.
D510: channel 1: open confirm rwindow 0 rmax 32768
D510: input_channel_request: rtype exit-status reply 0
D510: channel 1: rcvd eof
D510: channel 1: output open -> drain
D510: channel 1: rcvd close
D510: channel 1: input open -> closed
D510: channel 1: close_read <==================Hang right here.

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      09-18-2007

Quoth Mav <(E-Mail Removed)>:
> On Sep 17, 10:23 am, Ben Morrow <(E-Mail Removed)> wrote:
> > Quoth "J. Gleixner" <(E-Mail Removed)>:
> >
> > > Mav wrote:

> >
> > > > In fact, The actual script I am working actually first generates the
> > > > public key on the PC side(for that PC), then append the public key
> > > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > > will not prompt the password. Any suggestion?

> >
> > > You have to authenticate to have SSH work. That authentication
> > > can be public key or by providing the password. You might want
> > > to look at the Expect module, to automate the initial authentication
> > > with the password. Probably the best route is if the ssh keys don't
> > > exist, then to have the script prompt for the password when it
> > > runs, and have it pass it to SSH, using Expect.

> >
> > No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> > I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> > log in with a password.

>
> I looks into the Net::SSH::W32Perl, when I tried to use that I got the
> error:
>
> use Net::SSH::W32Perl;
> my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
>
> The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
> Perl.pm line
> 110.
>
> line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
> you encounter the same problem? That means that I have to set the
> $HOME in my script?


Err... yes, looks like it. I always have %HOME% set to my profile
directory anyway under Win32... I guess this could be reported as a bug
in N:S:W32Perl or N:Serl: the correct answer would be to use
File::HomeDir. You should probably put

use File::HomeDir;
BEGIN { $ENV{HOME} ||= File::HomeDir->my_data }

at the top, which will cause N:Serl to look for its config file in
Local Settings\Application Data\.ssh\config . Alternatively, if you
already have an OpenSSH config file elsewhere, simply direct N:S:W32Perl
at it: you will still need to set $ENV{HOME}, even though it will be
ignored.

Ben

 
Reply With Quote
 
Mav
Guest
Posts: n/a
 
      09-19-2007
On Sep 17, 5:02 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Mav <(E-Mail Removed)>:
>
>
>
> > On Sep 17, 10:23 am, Ben Morrow <(E-Mail Removed)> wrote:
> > > Quoth "J. Gleixner" <(E-Mail Removed)>:

>
> > > > Mav wrote:

>
> > > > > In fact, The actual script I am working actually first generates the
> > > > > public key on the PC side(for that PC), then append the public key
> > > > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > > > will not prompt the password. Any suggestion?

>
> > > > You have to authenticate to have SSH work. That authentication
> > > > can be public key or by providing the password. You might want
> > > > to look at the Expect module, to automate the initial authentication
> > > > with the password. Probably the best route is if the ssh keys don't
> > > > exist, then to have the script prompt for the password when it
> > > > runs, and have it pass it to SSH, using Expect.

>
> > > No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> > > I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> > > log in with a password.

>
> > I looks into the Net::SSH::W32Perl, when I tried to use that I got the
> > error:

>
> > use Net::SSH::W32Perl;
> > my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);

>
> > The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
> > Perl.pm line
> > 110.

>
> > line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
> > you encounter the same problem? That means that I have to set the
> > $HOME in my script?

>
> Err... yes, looks like it. I always have %HOME% set to my profile
> directory anyway under Win32... I guess this could be reported as a bug
> in N:S:W32Perl or N:Serl: the correct answer would be to use
> File::HomeDir. You should probably put
>
> use File::HomeDir;
> BEGIN { $ENV{HOME} ||= File::HomeDir->my_data }
>
> at the top, which will cause N:Serl to look for its config file in
> Local Settings\Application Data\.ssh\config . Alternatively, if you
> already have an OpenSSH config file elsewhere, simply direct N:S:W32Perl
> at it: you will still need to set $ENV{HOME}, even though it will be
> ignored.
>
> Ben


Thanks Ben. Look like when I download the package from here:
http://www.soulcage.net/ppds/

It doesn't have that problem.

Thanks,
Mav

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
prompt to save on exit - disable prompt on save button Mel ASP .Net 10 02-13-2009 05:32 AM
Change a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 1 01-16-2009 02:56 PM
Changing a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 2 01-16-2009 02:08 PM
How to open a shell prompt from an existing shell prompt gaurav kashyap Python 3 10-31-2008 04:41 AM
How to open a shell prompt from an existing shell prompt gaurav kashyap Python 2 10-30-2008 09:18 AM



Advertisments