Linux中如何授予某些用户修改hosts文件的权限

发布于 2025-01-05 11:46:04 字数 127 浏览 5 评论 0原文

现在我想在我们的系统中提供一个功能来修改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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彩扇题诗 2025-01-12 11:46:04

要将用户设置为 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.

戈亓 2025-01-12 11:46:04

最安全的选择是编写一个以受控方式修改文件的程序,然后使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文