English 中文(简体)
允许使用苯并二甲苯胺粉碎。
原标题:Allowing a PHP script to ssh, using sudo
  • 时间:2012-01-12 21:41:05
  •  标签:
  • apache
  • sudo

我需要允许在我的当地网络服务器上使用PHP文字,允许SSH向另一台机器提供特定任务,处理某些档案。 www.un.org/Depts/DGACM/index_spanish.htm 作为<条码>的,允许度低,因此难以设立没有密码的直接密码,而不是说不明智。

现在我这样做的方法是,要有一个最起码的双管齐下手套,可以把双管齐下(作为我)放在文件根基之外。 印本反过来又打电话(作为我)说,PHP代码实际从事SSH工作,并印刷其产出。 这部法典。

read_remote_files.php (我从我的浏览器打字):

exec( sudo -u me -n /home/me/run_php.sh /path/to/my_prog.php , $results);
print $results;

/home/me/run_php.sh (作为我,我说的是:

php $1 2>&1

www.un.org/Depts/DGACM/index_spanish.htm

_www ALL = (me) NOPASSWD: /home/me/run_php.sh

This all works, as my_prog.php is called as me and can SSH as me. It seems it s not too insecure since run_php.sh can t be called directly from a browser (outside document root). The issue I m having is that my_prog.php isn t called as an HTTP program so doesn t have access to the HTTP environment variables (DOCUMENT_ROOT etc).

两个问题:

  1. Am I making this too complicated?
  2. Is there an easy way for my final script to get the HTTP variables?

Thanks! Andy

最佳回答

“我需要允许在我的当地网络服务器上使用PHP文字,允许SSH向另一个机器提供某种文件的具体任务”。

我认为,你正在从solution<>em>的角度看待这一点。 您难以工作,而不是requirement。 当然,你应该说的是,“我想从一个PHP的纸面上援引机器B的任务,该书在机械A帕奇下运行。 之后,研究解决这一问题的办法——从一个简单的滚动式的RPC隧道,到使用XMLRPC或SOA框架,有许多。

两处:

  • Do a phpinfo(); on both machines to check what extensions are available and
  • Also check your php.ini setting to make sure that your service provider hasn t disabled any functions that you expect to use (or do a Q&D script to echo disable_functions = . ini_get( disable_functions ) . " "; ...)

如果你在这里和更广泛的互联网上浏览,你就会发现许多例子:Here是我用于类似目的的。

问题回答

很多系统使用经常检查档案、数据库记录或某些其他资源的(低层)招工,就象这样,然后采取行动。

其巨大优势是,购买力平价文字和特权文字之间根本不存在直接互动。 PHP的文字将指令放在资源上,即特权的文字。 只要指令可能导致系统受损或损坏,就会变得安全,而不是起诉。

不利之处是,你可以像你一样推动变革;你必须等到任后再工作。 但是,这或许是一个选择吗?





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...