Hi, Monks.
I'm having problems with using SSH/ssh-agent with Perl through CGI.

The Facts:
1. I've installed SSH and ssh-agent.
If I login as a user it works great.

2. I've programmed a perl script with Net::SSH:Perl.
It's all right with that. It uses PublicKey auth.

3. I've installed keychain (by Gentoo), this way I can access ssh-agent from any new session (with my working user).
It worked great.

4. Now I've developed a CGI page that access the same way that my Perl script.

This point is not working.

I imported manually the environment vars like HOME (through CGI you haven't access to them).
I've hacked the code and I reached the point that I found a problem in Net::SSH:Perl::AuthMgr, whe executes the "run" method. It tries to authenticate through public key, but it seems to be erasing my keys. So It ask me again for the passphrase.
Indeed, after that if I try to access manually the ssh conection it ask my for the passphrase.

I "googled" this problem, I looked for it here in PerlMonks, but I can't find a solution.

Thanks in advance. Regards.

Juan Matias


UPDATE Sep 07 2007
Hi, dudes. It's solved.
I was looking for a complex problem to solve. But, like in almost all cases, the solution is simple.

The app arquitecture I develop is working fine.
What's the problem?
At the very beginning of my program, I executed from the CGI the keychain script. Then I captured the STDOUT to set manualy the env vars corresponding to keychain.
Ok, my mistake, in one var string, parsed with regexp, there was a '\0'... so I cutted it...

Now it's working ok. The CGI run commands into a reomte server through ssh, with public/private key pairs, without need passphrases...

Thanks to all Monks...


I wrote in my page (spanish) how did I do this.
http://juanmatias.googlepages.com/perl-apache-ssh

In reply to CGI, SSH, PublicKey and keychain doesn't work by juanmatias

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.