Linux中如何授予某些用户修改hosts文件的权限
现在我想在我们的系统中提供一个功能来修改Linux中的系统hosts文件,但是运行系统的用户不是root,也不属于root组。 有没有办法授予用户对系统hosts文件的修改权限? (无需将此用户添加到 root 中)
谢谢。
Now I want to provide a function in our system to modify the system hosts file in Linux, but the user who runs the system is not root nor in root group.
Is there a way to grant a user the modification right on system hosts files? (without add this user into root)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将用户设置为 sudoer(具有更多权限的用户),您必须编辑 /etc/sudoers。
输入“sudo nano /etc/sudoers”并添加具有授予权限的用户!
您需要将以下行添加到 sudoers 文件中 - 例如:
user ALL=/etc/hosts --user 有权修改主机文件
,其中用户需要更改为该用户的真实用户名。
To set user as sudoer (user with more rights) you must edit /etc/sudoers.
Type "sudo nano /etc/sudoers" and add your user with granted permition!
You need to add the following line to the sudoers file - for example:
user ALL=/etc/hosts --user has right to modify hosts file
where user needs to be changed to real username of that user.
最安全的选择是编写一个以受控方式修改文件的程序,然后使用 sudo 向选定的用户授予运行该程序的权限。
或者您也可以使用 ACL:
setfacl/getfacl
。Your safest bet is to write a program that modifies the file in a controlled way and then grant the permission to run that program to the selected users using
sudo
.Or you could also use ACLs:
setfacl/getfacl
.