How to execute remote ssh command - Perl and CGI

Hi,

I am having nightmare issue-ing remote ssh command from a CGI perl script.
It just won't run on debug message: It says permission denied. Can I even do this? as the apache server running under DAEMON account probably can't execute it? Is this the case of what's going on?

Here is my snippet:

system ("ssh 172.16.10.12","htpasswd -b /etc/squid/squid_passwd $user_name $pass_word");
                if ($? == -1) {
                        print "Command Failed: $!\n";
                } else {
                        print "Command exited with value %d", $? >>8;
                }

I have tried using the backtick way and execute way too but I just can't get it. The apache box from where the CGI script is executed and the ssh box in question ARE setup for passwordless ssh auth and it works fine.

Any help is highly appreciated.

Thanks.

You should use the ssh command where you specify the account you want to use to login to the remote system. For example ssh root@172.16.10.12. Then you should have the keys setup to allow you to run the command with no passwords and such.

Hi,

I have tried this already "ssh root@172.16.10.12" but it gives me the same result, Permission Denied.

Thx

Ok..I got it to work finally..this is how I did it:

First user under which apache is running, I enabled for login only to generate the rsa.pub key. Added the rsa.pub key for the user to the authorized keys on the remote server (172.16.10.12). I then again disabled the login on that user.

Additionaly,

Here are the changes I made to my script:

system ("ssh root\@172\.16\.10\.12 htpasswd -b /etc/squid/squid_passwd \'$suser\' \'$spass\'");

I have this working now.

Thanks all for your help.