【问题标题】:Restart/Stop Nginx using my UserId without sudo permissions在没有 sudo 权限的情况下使用我的 UserId 重新启动/停止 Nginx
【发布时间】:2018-06-25 09:16:33
【问题描述】:

我需要在没有 sudo 帮助的情况下使用我的用户 ID 即 TAG1 重新启动通过 root 安装的 nginx 服务。现在我们正在使用以下命令重新启动服务

**COmmand : sudo /usr/bin/systemctl restart nginx**

So please provide us with some inputs how to restart nginx services using a newid without using SUDO permissions.

【问题讨论】:

    标签: nginx service sudo restart systemctl


    【解决方案1】:

    答案: 使用 visudo,将以下内容添加到您的 sudoers 文件中,将用户名替换为正确的用户名

    USER        ALL = NOPASSWD: /usr/bin/systemctl restart nginx
    

    这将允许用户使用任何或零以下属性(即 start|stop|restart)运行“/usr/bin/systemctl restart nginx”。

    更多细节参考:

    https://askubuntu.com/questions/692701/allowing-user-to-run-systemctl-systemd-services-without-password

    https://serverfault.com/questions/69847/linux-how-to-give-a-user-permission-to-restart-apache

    【讨论】:

    • 我尝试了上述步骤。编辑了 visudo sudoers 文件并在文件末尾添加了这一行 tag1 ALL = NOPASSWD: /usr/bin/systemctl restart nginx 。保存了那个文件。出口。尝试使用我的用户运行 /usr/bin/systemctl restart nginx 。错误:无法重新启动 nginx.service。需要交互式身份验证
    • 前面少了一个“sudo”,所以正确的调用应该是:'sudo /usr/bin/systemctl restart nginx'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多