473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Net::SSH::Perl

Hi all,

Below is my script that will be used to connect to a remote host and
change my password automatically:

===========================================
#!/usr/bin/perl
use strict();
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="xxx.xxx.xxx.xxx";
$old_password="password";
$new_password="newpass";
my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
$ssh->login($user, $pass);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
if ($str eq "Enter login password: ") {
$channel->send_data($old_password);
}
elsif ($str eq "New password: ") {
$channel->send_data($new_password);
}

elsif ($str eq "Re-enter new password: ") {
$channel->send_data($new_password);
}
});
$ssh->cmd('passwd');
==========================================

After running the program, my password didnt changed I was still able to
connect using the old password.

Does anybody has an idea what's missing or wrong with my script?

Thanks.

Jaws

Jul 19 '05 #1
3 21731
Sorry, I cant comment on the perl as yet but, are you not in the least bit
worried that someone might hack into your base system - get the unencrypted
password (old password) then log on - using ssh to the other box ?

ssh is not 100% flawless

From a security point of view it is a nightmare, from a SA point of view - I
can see where you are coming from !

Just curious is all
"blob" <ja**@skyinet.net> wrote in message news:3f******@news.skyinet.net...
Hi all,

Below is my script that will be used to connect to a remote host and
change my password automatically:

===========================================
#!/usr/bin/perl
use strict();
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="xxx.xxx.xxx.xxx";
$old_password="password";
$new_password="newpass";
my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
$ssh->login($user, $pass);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
if ($str eq "Enter login password: ") {
$channel->send_data($old_password);
}
elsif ($str eq "New password: ") {
$channel->send_data($new_password);
}

elsif ($str eq "Re-enter new password: ") {
$channel->send_data($new_password);
}
});
$ssh->cmd('passwd');
==========================================

After running the program, my password didnt changed I was still able to
connect using the old password.

Does anybody has an idea what's missing or wrong with my script?

Thanks.

Jaws

Jul 19 '05 #2
On Fri, 05 Sep 2003 10:07:49 -0800
blob <ja**@skyinet.net> wrote:
Hi all,

Below is my script that will be used to connect to a remote host and

change my password automatically: <sniped for brevity>
After running the program, my password didnt changed I was still
able to connect using the old password.

Does anybody has an idea what's missing or wrong with my script?


Just a suggestion - you may wish to use one of the Expect modules for
what you're doing. Expect is, IMHO, better suited for this task. And
in true Perl fashion, there is a module to interact with Expect :)

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Hlade's Law: If you have a difficult task, give it to a lazy
person -- they will find an easier way to do it.
Jul 19 '05 #3
On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:
Hi all,

Below is my script that will be used to connect to a remote host and
change my password automatically:

===========================================
#!/usr/bin/perl
use strict();
use Net::SSH::Perl;
$user="jaws";
$pass="password";
$host="xxx.xxx.xxx.xxx";
$old_password="password";
$new_password="newpass";
my $ssh = Net::SSH::Perl->new($host,debug=>1,use_pty=>1);
$ssh->login($user, $pass);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
if ($str eq "Enter login password: ") {
$channel->send_data($old_password);
}
elsif ($str eq "New password: ") {
$channel->send_data($new_password);
}

elsif ($str eq "Re-enter new password: ") {
$channel->send_data($new_password);
}
});
$ssh->cmd('passwd');
==========================================

After running the program, my password didnt changed I was still able to
connect using the old password.

Does anybody has an idea what's missing or wrong with my script?

Thanks.

Jaws


Instead of waiting for the exact string, why not use regular expresions,
which might eliminate typo's. Something like:

if ($str =~ /enter\s+login\s+password/i ) {
$channel->send_data($old_password);
}
elsif ($str =~ /new\s+password/i ) {
$channel->send_data($new_password);
}

elsif ($str =~ /re.enter\s+new\s+password/i ) {
$channel->send_data($new_password);
}

Cheers

--
Nico Coetzee

http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/

To the systems programmer, users and applications serve only to provide a
test load.

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SSDD | last post by:
Web host does not have SSH/Telnet, but I read somethink like you can open a SSHd or Telnetd with PHP or Perl. I am not sure if there will be an interface via PHP/Perl so that it will sends commands...
0
by: blob | last post by:
Hi all, Below is my script that will be used to connect to a remote host and change my password automatically: =========================================== #!/usr/bin/perl use strict();
2
by: Dmitry | last post by:
Hi folks! I need to find a way to switch to a different Unix user from within the Perl script that is currently ran unattended. Script must switch user in order to execute proper profile for...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
3
by: surajsingh | last post by:
Hi, I have a perl script which uses Net::Telnet module to open a telnet session with my unix boxes, and executes lot of commands on those boxes. As this module is implemented, when 'cmd' is...
12
by: jcor | last post by:
Hi, I'm using Ubuntu 7.04. I'm writing a sript that sends files via ftp for several destinations. So far I used Net::FTP and it worked fine. My problem is that I need to send files via SFTP...
1
by: kriz4321 | last post by:
Hi All, I need to connect to a remote server using perl. The server is SSH enabled and I find it difficult to Install Net::SSH::Perl as it has many modules as prereq. I have Installed NET:Telnet...
4
by: mail2sanand | last post by:
Hi All, I am trying to create a folder with "&" in itz name (Ex: TS_&_ABC) with the help of perl's ssh command in another server. The exact command I am triggering in the code is ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.