juanmatias has asked for the wisdom of the Perl Monks concerning the following question:
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
Comment on CGI, SSH, PublicKey and keychain doesn't work