douzhongju8780 2019-06-11 16:29
浏览 135

如何在不更改所有者或组的情况下创建或编辑非www-data拥有或分组的文件?

My PHP script create a ssh key pair and safe (file_put_contents) it to /home/pi/.ssh/. This script works fine from command line. But executing it from website (as www-data user) fails: "Warning: file_put_contents(/home/pi/.ssh/...) failed to open stream: Permission denied".

I don't want to change files group or owner. (i tried for tests and it works).

I don't want to use an extra scipt for this file editing.

I saw this question: allow php files to write to locations other than those owned by www-data This solution is not what i was looking for.

I tried to add the path (/home/pi/.ssh/) and path+filname to /etc/sudoers. This not working. It seems that sudoers is for executable files only?!

I would wish a solution like an entry in /etc/sudoers. Because there will be some more files "outside the webserver" that needed to edit from website.

So please tell me, is there another easy option?

  • 写回答

1条回答 默认 最新

  • drhg24275 2019-06-12 02:22
    关注

    What you are trying to do sounds like a super dangerous thing.

    If you have access to the server, maybe you can trying using PHP to simply trigger the creation of the SSH key pair. Then a script on the server (a cront job for example) will create the key using root permission for example, then place then in a folder that PHP has access to.

    What I am trying to say is to simply delegate that task to another script that has more privilege than www-data.

    评论

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致