dputlf5431 2017-10-16 11:18
浏览 46

如何让ssh-agent访问由php-data(apache)执行的php脚本?

Is there a way, to give www-data (apache) access on ssh-agent? I have a simple php (cli) script, which simply connects a remote ssh server and run a simple command. On CLI I first start ssh-agent and load key which I protected by a passphrase.

Load agent a key:

# eval $(ssh-agent -s)
# ssh-add /root/.ssh/id_rsa

PHP CLI script:

#!/usr/bin/php
<?php

$connection = ssh2_connect('host', 22);

if (ssh2_auth_agent($connection, 'username')) {
  echo "Authentication Successful!
";
} else {
  die('Authentication Failed...');
}

$stream = ssh2_exec($connection, 'sh int status');
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);

echo stream_get_contents($stream_out);

On CLI this works fine, but when I run the above snippet under apache, I can't authenticate on remote ssh host. I think the issue is, that the php/apache has no access on the ssh-agent.

My question: is there a way to start ssh-agent and load key for apache, so that apache has access on it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大