CentOS7下普通账号通过systemctl管理服务需要输入root密码问题

解决CentOS7中普通用户通过systemctl管理服务需输入root密码的问题,通过修改/usr/share/polkit-1/actions/org.freedesktop.systemd1.policy文件,将manage-units动作的默认授权设置为yes,允许无密码操作,然后重启polkit服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CentOS7下普通账号通过systemctl管理服务需要输入root密码问题
CentOS7下 普通账号通过 systemctl 管理服务

CentOS7下 普通账号通过 systemctl 管理服务

问题描述:

使用普通账号test通过systemctl启动系统服务提示需要输入root密码:

[test@host-192-168-65-94 data]$ systemctl restart nginx
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 

解决方案:

根据上面提示得知权限由polkit进行管理,对应的是org.freedesktop.systemd1.policy这个配置文件下的manae-units动作

进入/usr/share/polkit-1/actions/org.freedesktop.systemd1.policy,将对应manae-unitsdefaults中的授权全部改为yes,然后执行systemctl restart polkit重启polkit

        <action id="org.freedesktop.systemd1.manage-units">
			------
			<defaults>
			<!--
			        <allow_any>auth_admin</allow_any>
                    <allow_inactive>auth_admin</allow_inactive>
                    <allow_active>auth_admin_keep</allow_active>
			-->
					<allow_any>yes</allow_any>
			        <allow_inactive>yes</allow_inactive>
			        <allow_active>yes</allow_active>
			 </defaults>
        </action>

权限可选的配置参数:

defaults 选项

This element is used to specify implicit authorizations for clients. Elements that can be used inside defaults include:

  • allow_any: Implicit authorizations that apply to any client. Optional.

  • allow_inactive: Implicit authorizations that apply to clients in inactive sessions on local consoles. Optional.

  • allow_active: Implicit authorizations that apply to clients in active sessions on local consoles. Optional.

Each of the allow_any, allow_inactive and allow_active elements can contain the following values:

  • no: Not authorized.

  • yes: Authorized.

  • auth_self: Authentication by the owner of the session that the client originates from is required. Note that this is not restrictive enough for most uses on multi-user systems; auth_admin* is generally recommended.

  • auth_admin: Authentication by an administrative user is required.

  • auth_self_keep: Like auth_self but the authorization is kept for a brief period (e.g. five minutes). The warning about auth_self above applies likewise.

  • auth_admin_keep: Like auth_admin but the authorization is kept for a brief period (e.g. five minutes).

优快云_码404:CentOS7下普通账号通过systemctl管理服务需要输入root密码问题

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leenhem

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值