CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Net::SSH::Perl ( Complex Password Fails? )

 



ezilagel
Novice

Oct 31, 2012, 10:01 AM

Post #1 of 13 (1975 views)
Net::SSH::Perl ( Complex Password Fails? ) Can't Post

I'm attempting to write a script that logins via ssh and provides an output of a command. However, it seems that when I try to login using a complex password, it fails to authenticate. Here is an example...


The below will fail to authenticate.
If I change the password on the remote user to simple word or a word with numbers it works fine.

Any idea?


Code
#!/usr/bin/perl 

use Net::SSH::Perl;

my $host = 'x.x.x.x';
my $user = 'user';
my $password = 'P@ssw@rd!';

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
$ssh->login($user, $password);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("uname -a");
print "$stdout\n";


Thanks.


Edit: Output of running the script when failing..

Permission denied at script.pl line 12

(This post was edited by ezilagel on Oct 31, 2012, 12:09 PM)


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:28 AM

Post #2 of 13 (1966 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Which line is 12, the $ssh->login statement or the $ssh->cmd statement?

Enable debug and then post the complete message.


(This post was edited by FishMonger on Oct 31, 2012, 11:28 AM)


ezilagel
Novice

Oct 31, 2012, 11:43 AM

Post #3 of 13 (1961 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

$ssh->login($user, $password);


Its not accepting the password because of the @.
Not sure how to use @ symbols in the pasword when using SSH in perl.

If I change the user password on the remote server to something like " newpass1 " it works. It just fails with the special characters.


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:48 AM

Post #4 of 13 (1959 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Are you using single quotes or double quotes around the password?

If you're using double quotes, then that would be the problem, because they enable variable interpolation and the @ symbol denotes a perl array. Use single quotes when you don't need/want interpolation.


ezilagel
Novice

Oct 31, 2012, 11:49 AM

Post #5 of 13 (1957 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

I used single quotes. You can see it on my code in the first post.


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:55 AM

Post #6 of 13 (1954 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Please enable debug as I previously requested and post the complete output.


ezilagel
Novice

Oct 31, 2012, 12:06 PM

Post #7 of 13 (1949 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post


Code
$ perl script.pl  
Permission denied at script.pl line 12 (#1)
(F) The setuid emulator in suidperl decided you were up to no good.

Uncaught exception from user code:
Permission denied at script.pl line 12
at /usr/local/share/perl5/Net/SSH/Perl.pm line 255
Net::SSH::Perl::fatal_disconnect('Net::SSH::Perl::SSH2=HASH(0x14d4d48)', 'Permission denied') called at /usr/local/share/perl5/Net/SSH/Perl/SSH2.pm line 69
Net::SSH::Perl::SSH2::login('Net::SSH::Perl::SSH2=HASH(0x14d4d48)', 'user', 'proper password displayed') called at script.pl line 12



(This post was edited by ezilagel on Oct 31, 2012, 12:08 PM)


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:08 PM

Post #8 of 13 (1945 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Are you able to connect from the command line using the same password?


ezilagel
Novice

Oct 31, 2012, 12:09 PM

Post #9 of 13 (1943 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Yes.


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:34 PM

Post #10 of 13 (1938 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Is the setuid bit set on the script?

Do you have root access and if so, do you get the same error when running the script as root?


ezilagel
Novice

Oct 31, 2012, 12:49 PM

Post #11 of 13 (1934 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Nothing set in the script.

If I execute the script with root privileges, it has the same error.

Been doing reading, it seems to be an issue with @ in the password. Can't figure out how to pass it to the ssh function in perl properly. Will update if I find something. The error is simply stating the password is not working. When it passes the password, its missing characters because of the @ symbols.


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:58 PM

Post #12 of 13 (1932 views)
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post


Quote
When it passes the password, its missing characters because of the @ symbols.

Since you're using single quotes that should not happen, unless the module is passing it thru eval before passing it to ssh.

I no longer have this module installed, but it sounds like this might be a bug in the module.

The normal recommendation by most would be to use the Net::SSH2 module instead. It is faster, and does not suffer from the enormous amount of dependencies.

http://search.cpan.org/~rkitover/Net-SSH2-0.45/lib/Net/SSH2.pm


ezilagel
Novice

Oct 31, 2012, 1:03 PM

Post #13 of 13 (1930 views)
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? ) [In reply to] Can't Post

Thanks for you help.

Unfortunately, it fails using Net::SSH2 module as well. It was actually the first script I wrote. I resorted to Net::SSH::Perl after trying other examples I found online. They all resulted the same. If the user has an @ symbol in the required password, it fails to authenticate.

Anyways, I appreciate you looking into this for me.

Edit: I'm actually thinking it might have to do with the double @ and !. (the password in the first post) I tried a password with just one @ and it seemed to work. However unfortunately for my use, the passwords are more complicated.


(This post was edited by ezilagel on Oct 31, 2012, 1:09 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives