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:
How to talk to ssh-agent in perl

 



tekka
New User

Mar 4, 2010, 9:26 AM

Post #1 of 3 (599 views)
How to talk to ssh-agent in perl Can't Post

Hello,
I have an environment where a perl script is run from inside a shell script.
The shell script start ssh-agent and ssh-add and I would like to use the environment variable SSH_AUTH_SOCK inside the perl.
My ssh key has a passphrase set and my goal would be this way I will be prompted for it only once by the shell script while some rdist subcommands inside the perl script will not ask for passhprase any more.
Supposing to do all in shell script (so a shell that calls another shell) I can reach this goal calling the inner shell script with something like:

env SSH_AUTH_SOCK=$SSH_AUTH_SOCK inner_script.sh

The same doesn't work ootb if the inner is a perl script.

I found Net::SSH::Perl::Agent that seems to be the thing for me but I don't understand how to use it to be able to inherit the key and automatically talk with the agent
Any hints/example?

The way rdist command is called inside the perl script is something like:
my $command="rdist";
open(RDIST, "$command 2>&1 |" ) ||
die("$basename: Unable to open $command\n");

my $errorcount = 0;
while ( <RDIST> ) {
... some other commands/statements
}

So I want the rdist command not to ask for passhprase for every host it has to process...

Thanks in advance,
Gianluca


FishMonger
Veteran / Moderator

Mar 4, 2010, 10:27 AM

Post #2 of 3 (595 views)
Re: [tekka] How to talk to ssh-agent in perl [In reply to] Can't Post

I'll leave the shell scripting aspect of your question to someone else.

For the Perl side, it would be better to use Net::SSH::Perl http://search.cpan.org/~turnstep/Net-SSH-Perl-1.34/lib/Net/SSH/Perl.pm and handle all ssh calls inside the Perl script.

If you're not going to use ssh key exchange, then you'll want the Perl script to prompt the user for their credentials. When entering the password, you'll want to disable echoing the terminal input and re-enable it after retrieving the password.


tekka
New User

Mar 4, 2010, 2:15 PM

Post #3 of 3 (589 views)
Re: [FishMonger] How to talk to ssh-agent in perl [In reply to] Can't Post

Thanks for answering.
But the shell script analogy is already solved by my example.
What I was searching for is instead a method
to talk to the ssh-agent from inside the perl so that I don't have
to type my passphrase (not password) for every host for
which rdist has to make its work...

In Reply To

 
 


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

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