Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Net::SSH::Perl with public keys?

Tags:

ssh

ssh-keys

perl

I'm trying to use Net::SSH::Perl to connect using public keys with this code:

my $ssh = Net::SSH::Perl->new($host, debug=>1) || die ......

I put the key in /root/.ssh/id_rsa and /root/.ssh/identity

It seems that it's not trying to use the public key and instead trying to ask for a password:

I get this output:


localhost: Sent key-exchange init (KEXINIT), wait response.
localhost: Algorithms, c->s: 3des-cbc hmac-sha1 none
localhost: Algorithms, s->c: 3des-cbc hmac-sha1 none
localhost: Entering Diffie-Hellman Group 1 key exchange.
localhost: Sent DH public key, waiting for reply.
localhost: Received host key, type 'ssh-dss'.
localhost: Host '10.212.1.201' is known and matches the host key.
localhost: Computing shared secret key.
localhost: Verifying server signature.
localhost: Waiting for NEWKEYS message.
localhost: Send NEWKEYS.
localhost: Enabling encryption/MAC/compression.
localhost: Sending request for user-authentication service.
localhost: Service accepted: ssh-userauth.
localhost: Trying empty user-authentication request.
localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password.
localhost: Next method to try is publickey.
localhost: Next method to try is password.
localhost: Trying password authentication.
localhost: Will not query passphrase in batch mode.
localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password.
localhost: Next method to try is publickey.
localhost: Next method to try is password.
localhost: Trying password authentication.
localhost: Will not query passphrase in batch mode.
localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password.
localhost: Next method to try is publickey.
localhost: Next method to try is password.
localhost: Trying password authentication.
localhost: Will not query passphrase in batch mode.
localhost: Authentication methods that can continue: publickey,gssapi-with-mic,password.
localhost: Next method to try is publickey.
localhost: Next method to try is password.
like image 998
Arthur Ulfeldt Avatar asked Aug 26 '10 18:08

Arthur Ulfeldt


People also ask

How public and private keys work in ssh?

Public And Private Key UsesThe private key is secret, known only to the user, and should be encrypted and stored safely. The public key can be shared freely with any SSH server to which the user wishes to connect.


1 Answers

found it: have to specify the key file location manually:

@KEYFILE = ("/root/.ssh/id_rsa");
$ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)
like image 187
Arthur Ulfeldt Avatar answered Sep 19 '22 02:09

Arthur Ulfeldt