在 PHP 中使用 exec() 执行 RSH 命令
我在 PHP exec()
命令中使用 rsh
时遇到问题。我收到的错误是:无法创建目录“/nonexistent/.ssh”
。
看来这是因为 Apache 以没有主目录的用户 nobody
身份运行,因此它无法找到/创建 .ssh 目录。我从终端执行的操作类似于:
sudo su - user_with_home_directory
/usr/bin/rsh -n -l username myserver.com /path/to/my/script.sh
但我不知道如何使用 PHP 的 exec() 命令来执行此操作。我不想(也不能)为无人用户提供主目录只是为了解决问题。
非常感谢任何帮助我弄清楚如何让它发挥作用的帮助。
I am having trouble using rsh
in the PHP exec()
command. The error that I'm getting is: Could not create directory '/nonexistent/.ssh'
.
It appears that this is because Apache runs as the user nobody
who does not have a home directory, therefore it cannot find/create a .ssh directory. What I would do from the terminal is something similar to:
sudo su - user_with_home_directory
/usr/bin/rsh -n -l username myserver.com /path/to/my/script.sh
But I am not aware of how to do this using PHP's exec()
command. I don't want to (and cannot) give the nobody user a home directory just to get the problem to go away.
Any help is greatly appreciated to helping me figure out how to get this to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我使用的服务器上的 rsh 似乎启用了 Kerberos,而服务器又使用 SSH 进行身份验证。这就是导致搜索
.ssh
目录的原因。为了解决这个问题,我创建了一个 SSH 密钥并将其存储在文件系统中除
.ssh
目录之外的其他位置,再次防止为nobody
创建主目录> 用户。然后使用 SSH,我指定了指向生成的 SSH 密钥的-i
选项,这样我就可以远程执行脚本,而无需使用密码登录。So it seems as if the
rsh
on the server that I'm using is Kerberos enabled, which in turn uses SSH to do the authentication. This is what was causing the search for a.ssh
directory.To solve this, I created an SSH key and stored it on the filesystem at a different location other than the
.ssh
directory, again to prevent from creating a home directory for thenobody
user. Then using SSH, I specified the-i
option that points to my generated SSH key, allowing me to execute the script remotely without the need to login with a password.