Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

get ssh key passphrase from agent

by ninto1 (Novice)
on Aug 30, 2022 at 13:19 UTC ( [id://11146496]=perlquestion: print w/replies, xml ) Need Help??

ninto1 has asked for the wisdom of the Perl Monks concerning the following question:

Hey There!

Disclaimer: I am very new to perl

I am currently working on connecting Simpack to a high performance cluster, which is why I need to use pubkey authentication, but don'T have any way for use input.

I am aware of the other thread about this, but it did not prove helpful for me.

I managed to create a passphrase protected Keypair, add it to the windows ssh agent and got it working in cmd, but it doesn's seem to quite work in perl. I already tried Net::OpenSSH, but couldn't seem to get a connection with the server.

I am currently using Net::SSH::Perl. It works fine with non protected keys, but this is not an option because of the strict security policies in the company I am working for. Also, it needs to work on windows, since the clients who are gong to use this are all running on windows.

Please let me know, if you got any ideas to solve this!

Thanks in advance - ninto

Crosspost: Stackoverflow

Replies are listed 'Best First'.
Re: get ssh key passphrase from agent
by Corion (Patriarch) on Aug 30, 2022 at 13:28 UTC

    Net::SSH2 claims to be able to do authentication through an agent. The other modules don't seem to do that, so I'm not sure if it is possible without using Net::SSH2.

    One thing I've done in such cases is to run commands through plink or ssh external binaries, but that only works for very limited use cases.

      I looked into it, and it seems to be just what I need!

      Imma just try to implement it, and I will let you know, once I definately know if it works

      Thank you a lot

        I tried to make a sample, which test everything I need from the module, but sadly I get an error, which I can't explain:

        failed connecting agent (-42 LIBSSH2_ERROR_AGENT_PROTOCOL) at .\sshtest.pl line 7.

        I think it should work, because the agent works just fine in CMD.

        I would appreciate any help!

Re: get ssh key passphrase from agent
by atcroft (Abbot) on Aug 30, 2022 at 23:39 UTC

    Poking around in Net::SSH::Perl and its components, a couple of things suggested themselves to me. First was Net::SSH::Perl::Key->read_private($key_type, $file [, $pass] ) that can read and decrypt a private key using $pass. That with Net::SSH::Perl::Util->_read_passphrase($prompt) might be an approach. While looking at Net::SSH::Perl::Util, though, there was also Net::SSH::Perl::Util->_load_private_key($key_file [, $passphrase]). There is also Net::SSH::Perl::Agent, which indicates it can interact as a client for agent-based publickey authentication.

    I know how much "fun" it can be dealing with SSH, so I hope some of the above is helpful.

      The Net:SSH:Perl:Agent module doesn't seem to work for me. I get the following error, even with the included sexample code.

      Can't call method "identity_iterator" on an undefined value at .\sshtest.pl line 5.

      This is the code I used:

      #!/usr/bin/perl -w use Net::SSH::Perl; use Net::SSH::Perl::Agent; my $agent = Net::SSH::Perl::Agent->new(1); my $iter = $agent->identity_iterator; while (my($key, $comment) = $iter->()) { print $key; }

      I think this means, that $agent is not defined, so Net::SSH::Perl::Agent->new didn't work. My ssh agent works fine in my shell directly with the ssh command tho.

      Please Let me know what I might be doing wrong.

      Thanks, Ninto!

        I don't get any error, but the script you posted doesn't output anything unless I change the version of the agent to 2.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11146496]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found