Reputation: 3080
I am trying to connect to a remote server and run ssh commands in my Perl script. I have provided the correct port, host, username and password. Using the same credentials I can properly login through terminal. When I provide the same in my code I get error response. Please help.
Here is my code:
use strict;
use Net::SSH::Perl;
my $hostname = "xxx.zzz.ccc.vvv";
my $username = "username";
my $password = "password";
my $cmd = "aws --version";
my $ssh = Net::SSH::Perl->new("$hostname", debug=>0, port=> 56789);
$ssh->login("$username","$password");
my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd");
print $stdout;
Here is the output:
Received disconnect message: Too many authentication failures for username
at /usr/local/lib/x86_64-linux-gnu/perl/5.26.0/Net/SSH/Perl/AuthMgr.pm line 157.
Upvotes: 1
Views: 613
Reputation: 118595
Your password is specified inside double quotes, and Perl will interpolate scalar and array variables inside double quotes.
$password = "qwer@345"; print $password; # "qwer"
If you use double quotes to enclose a string, you must escape any special characters in that string such as $
, @
, "
, or \
.
$password = "qwer\@345"; print $password; # "qwer@345"
or use single quotes -- Perl does not do interpolation inside single quotes.
$password = 'qwer@345'; print $password; # "qwer@345"
If you use warnings
(you always use warnings
, don't you?), sometimes Perl will warn you when something you write in double quotes might get misinterpreted.
Upvotes: 2