编辑sudoers文件未生效

时间:2017-05-02 09:40:34

标签: php linux rights sudoers

嘿同事们,

我正在攻读我的学士学位项目,并遇到了一些问题。

目标是创建一个Web应用程序,可以操作和修改WAGO PLC 750-8202(您可以将其视为某种工业Raspberry PI)的I / O运行带有lighttpd Web服务器的嵌入式Linux。我已经制作了一些利用PLC提供的DAL(HAL)功能的C脚本。

现在我想将它与我的网络应用程序/网站链接。我有一个简单的PHP页面(忽略按钮,它什么都不做):

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <button value="CLICK ME">CLICK ME</button>
<?php
echo system("kbusdemo1");
?>
 </body>
</html>

kbusdemo1执行但没有正确使用DAL提供的功能,它给了我一个错误。如果我以root身份运行该脚本,它就能完美运行。我发现问题出在www用户权限(我的web服务器lighttpd使用),所以我尝试用

编辑sudoers
sudo nano /etc/sudoers

Visudo未在PLC linux系统中实现,因此我必须直接打开它。我将其更改为下面发布的代码,但是如果我尝试将c脚本作为lighttpd用户运行(使用su www),它仍然无法正常工作。我做错了什么?

谢谢你的建议。

# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# Runas alias specification

# User privilege specification 
root  ALL=(ALL) SETENV: ALL 
admin ALL=NOPASSWD: /etc/config-tools/get_user_info user 
ALL=NOPASSWD: /etc/config-tools/get_user_info 
www ALL=(ALL) NOPASSWD:ALL

# Uncomment to allow people in group wheel to run all commands
# and set environment variables.
# %wheel  ALL=(ALL) SETENV: ALL

# Same thing without a password
# %wheel  ALL=(ALL) NOPASSWD: SETENV: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

1 个答案:

答案 0 :(得分:0)

感谢您的帮助。我得到了它的工作,我没有从PHP文件调用脚本作为sudo。正如你的建议,我改变了sudoers中的行只允许一个特定的脚本,所以没有安全漏洞。

相关问题