Question on input password on ssh prompt

M

Mav

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
 
B

Ben Morrow

Quoth Mav said:
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.
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
 
M

Mav

Quoth Mav <[email protected]>:







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.


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


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
 
J

J. Gleixner

Mav said:
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.
 
B

Ben Morrow

Quoth "J. Gleixner said:
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
 
M

Mav

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
 
M

Mav

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::perl 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.
 
M

Mav

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::perl 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.
 
B

Ben Morrow

Quoth Mav said:
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:S:perl: 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:S:perl 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
 
M

Mav

Quoth Mav <[email protected]>:








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:S:perl: 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:S:perl 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
 
M

Mav

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

It doesn't have that problem.

Thanks,
Mav

Well, I guess now it comes to another problem..using Par-packer(pp).
My perl (5.8.7 Build 813) on the PC, I have got a Par-packer version
that works with my perl version.
The W32Perl module install on


----------
#This is y.pl
use Net::SSH::W32Perl;
$host = "192.168.0.101";
$user = "user";
$passwd = "passwd";

my $ssh = new Net::SSH::W32Perl($host,protocol => '2,1',debug
=>1,options => ["BatchMode yes", "RhostsAuthentication no" ]);
$ssh->login($user, $passwd);
my ($out, $err, $exit) = $ssh->cmd('ls -la');

----------------

The code works fine if I do.
perl y.pl

However when I tried to using pp to create a a.exe
----------
c:\myperl>pp -o a.exe y.pl

c:\myperl>a.exe
pc: Reading configuration data /.ssh/config
pc: Reading configuration data /etc/ssh_config
pc: Connecting to 192.168.0.101, port 22.
pc: Socket created, turning on blocking...
pc: Remote protocol version 2.0, remote software version OpenSSH_4.3p2
Debi
an-9
Can't locate Net/SSH/W32Perl/SSH2.pm in @INC (@INC contains: C:
\DOCUME~1\Maveri
k\LOCALS~1\Temp\par-user\cache-1190269914/inc/lib C:\DOCUME~1\user
\LOCA
S~1\Temp\par-user\cache-1190269914/inc CODE(0xe8d788) .) at Net/SSH/
Perl.pm
line 55, <GEN3> line 1.
-----

my SSH2.pm is install in

C:\myperl>dir c:\perl\site\lib\Net\SSH\W32Perl\
Volume in drive C has no label.
Volume Serial Number is B04F-3453

Directory of c:\perl\site\lib\Net\SSH\W32Perl

09/18/2007 09:09 PM <DIR> .
09/18/2007 09:09 PM <DIR> ..
10/22/2002 06:16 AM 560 SSH2.pm

is that something I am missing when doing pp?

Thanks,
Mav
 
M

Mav

Thanks Ben. Look like when I download the package from here:http://www.soulcage.net/ppds/
It doesn't have that problem.
Thanks,
Mav

Well, I guess now it comes to another problem..using Par-packer(pp).
My perl (5.8.7 Build 813) on the PC, I have got a Par-packer version
that works with my perl version.
The W32Perl module install on

----------
#This is y.pl
use Net::SSH::W32Perl;
$host = "192.168.0.101";
$user = "user";
$passwd = "passwd";

my $ssh = new Net::SSH::W32Perl($host,protocol => '2,1',debug
=>1,options => ["BatchMode yes", "RhostsAuthentication no" ]);
$ssh->login($user, $passwd);
my ($out, $err, $exit) = $ssh->cmd('ls -la');

----------------

The code works fine if I do.
perl y.pl

However when I tried to using pp to create a a.exe
----------
c:\myperl>pp -o a.exe y.pl

c:\myperl>a.exe
pc: Reading configuration data /.ssh/config
pc: Reading configuration data /etc/ssh_config
pc: Connecting to 192.168.0.101, port 22.
pc: Socket created, turning on blocking...
pc: Remote protocol version 2.0, remote software version OpenSSH_4.3p2
Debi
an-9
Can't locate Net/SSH/W32Perl/SSH2.pm in @INC (@INC contains: C:
\DOCUME~1\Maveri
k\LOCALS~1\Temp\par-user\cache-1190269914/inc/lib C:\DOCUME~1\user
\LOCA
S~1\Temp\par-user\cache-1190269914/inc CODE(0xe8d788) .) at Net/SSH/
Perl.pm
line 55, <GEN3> line 1.
-----

my SSH2.pm is install in

C:\myperl>dir c:\perl\site\lib\Net\SSH\W32Perl\
Volume in drive C has no label.
Volume Serial Number is B04F-3453

Directory of c:\perl\site\lib\Net\SSH\W32Perl

09/18/2007 09:09 PM <DIR> .
09/18/2007 09:09 PM <DIR> ..
10/22/2002 06:16 AM 560 SSH2.pm

is that something I am missing when doing pp?

Thanks,
Mav

Well, I guess I find my answer:
pp -v -o a.exe --lib=C:\Perl\site\lib --module=Net/SSH/W32Perl/SSH2.pm
x.pl

Thanks,

Mav
 
B

Ben Morrow

[this is really a different problem: with PAR instead of with ssh, so it
would have been better to start a new thread.]

Quoth Mav said:
Well, I guess now it comes to another problem..using Par-packer(pp).
My perl (5.8.7 Build 813) on the PC, I have got a Par-packer version
that works with my perl version.
The W32Perl module install on

----------
#This is y.pl
use Net::SSH::W32Perl;
$host = "192.168.0.101";
$user = "user";
$passwd = "passwd";

my $ssh = new Net::SSH::W32Perl($host,protocol => '2,1',debug
=>1,options => ["BatchMode yes", "RhostsAuthentication no" ]);
$ssh->login($user, $passwd);
my ($out, $err, $exit) = $ssh->cmd('ls -la');

----------------

The code works fine if I do.
perl y.pl

However when I tried to using pp to create a a.exe
----------
c:\myperl>pp -o a.exe y.pl

c:\myperl>a.exe
pc: Reading configuration data /.ssh/config
^^^
This is probably wrong... do you have %HOME% set to the empty string, or
is your copy of Net::SSH::perl different?

Can't locate Net/SSH/W32Perl/SSH2.pm in @INC (@INC contains: C:
my SSH2.pm is install in
is that something I am missing when doing pp?

Well, what happened when you tried including Net::SSH::W32Perl::SSH2 in
the PAR explicitly?

pp -o a.exe -M Net::SSH::W32Perl::SSH2 y.pl

I can't try it here as I don't have a Win32 machine on hand atm.

Ben
 
M

Mav

[this is really a different problem: with PAR instead of withssh, so it
would have been better to start a new thread.]

Quoth Mav <[email protected]>:


Well, I guess now it comes to another problem..using Par-packer(pp).
My perl (5.8.7 Build 813) on the PC, I have got a Par-packer version
that works with my perl version.
TheW32Perlmodule install on
----------
#This is y.pl
use Net::SSH::W32Perl;
$host = "192.168.0.101";
$user= "user";
$passwd = "passwd";
my $ssh= new Net::SSH::W32Perl($host,protocol => '2,1',debug
=>1,options => ["BatchMode yes", "RhostsAuthentication no" ]);
$ssh->login($user, $passwd);
my ($out, $err, $exit) = $ssh->cmd('ls -la');
----------------

The code works fine if I do.
perl y.pl
However when I tried to using pp to create a a.exe
c:\myperl>a.exe
pc: Reading configuration data /.ssh/config

^^^
This is probably wrong... do you have %HOME% set to the empty string, or
is your copy of Net::SSH::perl different?

Can't locate Net/SSH/W32Perl/SSH2.pm in @INC (@INC contains: C:
my SSH2.pm is install in
is that something I am missing when doing pp?

Well, what happened when you tried including Net::SSH::W32Perl::SSH2 in
the PAR explicitly?

pp -o a.exe -M Net::SSH::W32Perl::SSH2 y.pl

I can't try it here as I don't have a Win32 machine on hand atm.

Ben

Hey, Ben
Thanks a lot, all my problem get solved. I really appericate your help
from beginning to the end. Happy Scripting! =)

Again, Thanks a lot.
Mav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top