Rajeev
Rajeev

Reputation: 46899

perl script to execute ssh command without using password

I have a faceless account on a remote machine.i.e, i do not have to insert my password when doing a ssh.My question is that what should be my code if i do not have to use the password through the perl code.In the shown code its still asking for a password

 $cmd="cat /read.log";
 my $ssh = Net::SSH::Perl->new($host, protocol => '1,2', debug => 1);
 $ssh->login($user, $pass);
 my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
 print $stdout, "\n";

Upvotes: 1

Views: 3376

Answers (2)

sergio
sergio

Reputation: 69027

You should give the identity_files argument to Net::SSH::Perl->new. Check where your identity files are located and compare to the module docs:

identity_files

A list of RSA/DSA identity files to be used in RSA/DSA authentication. The value of this argument should be a reference to an array of strings, each string identifying the location of an identity file. Each identity file will be tested against the server until the client finds one that authenticates successfully.

If you don't provide this, RSA authentication defaults to using $ENV{HOME}/.ssh/identity, and DSA authentication defaults to $ENV{HOME}/.ssh/id_dsa.

Upvotes: 1

freespace
freespace

Reputation: 16701

While standard ssh checks for id_rsa and id_dsa in your ~/.ssh/ folder when using challenge-response authentication, Net::SSH::Perl only looks in $ENV{HOME}/.ssh/identity for RSA and $ENV{HOME}/.ssh/id_dsa for DSA. I suspect this is the cause of the problem, and you can solve this by adding identity_files to the parameters passed to the new method.

Check your identities by executing ls ~/.ssh/ and look for a file called id_rsa. Then simply set identity_files to include the appropriate paths.

Upvotes: 1

Related Questions