LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   using SSH in PHP invokes 'Host Key Verification Failed' error (http://www.linuxquestions.org/questions/programming-9/using-ssh-in-php-invokes-host-key-verification-failed-error-834697/)

chuafengru 09-27-2010 04:28 AM

using SSH in PHP invokes 'Host Key Verification Failed' error
 
Hi all,

Im trying to do a remote execution of scripts through SSH in PHP.

What im doing:
-Use PHP in conjunction with nagios' check_by_ssh script to execute the script.
-I used
Code:

$output = shell_exec('cd /usr/local/nagios/libexec && ./check_by_ssh -H server01 -l nagios -C "/server01/nagios/plugin/check_memory"');
-It gives me a 'Host key verification failed' error even though i enabled it to ssh from my server to server01 without password.

My Qn:
How do i get it to work?

Meson 09-27-2010 08:40 AM

You need an entry in your known_hosts file. There's a system wide one as well as a per-user one. You can just manually run an ssh connection to that server, and then put it's hostkey in your system-wide known_hosts file. I'm not sure but you may need to clean out the PHP users too.

Also, I know PHP has some built in SSH functionality, are you sure you want to be calling a shell process for this?

chuafengru 09-27-2010 08:32 PM

Hi,

im currenly tapping on the ssh script for testing purpose. If possible, it will introduce a much simpler solution for my case :) I will give it a try on the system wide known hosts file.

Thanks for your feedback.

dinglebat 10-01-2010 01:26 PM

Quote:

Also, I know PHP has some built in SSH functionality, are you sure you want to be calling a shell process for this?
The built in functionality isn't present on most servers and even on those it is present on it has a reputation for being buggy and difficult to use.

In my experience, the best way to do SSH from PHP is with phpseclib, a pure PHP SSH client. To do what you're trying to do you'd do something like....

$ssh = new Net_SSH2();
$ssh->login('...', '...');
echo $ssh->exec('...');


All times are GMT -5. The time now is 04:09 AM.