如何在普通用户中使用Virt-Manager,Libvirt,而无需root特权和密码

本文介绍了如何在Linux系统中使用Polkit(PolicyKit)允许普通用户无须root权限和密码就能运行Virt-Manager和Libvirt。通过创建虚拟化组、将用户加入该组以及制定Polkit规则,可以实现无密码运行虚拟化工具。
摘要由CSDN通过智能技术生成

Virt-manager and libvirt is core tools used for virtualization in Linux ecosystem. As a end user I am using these tools to create and run virtual machines. I am running this tools as normal user without using privileged user like root But every time I try to run these tool the sudo password is asked me. This become a nightmare after some time. Are there any solution to run these tools without putting password and changing any permission in virtualization side. Yes.

Virt-manager和libvirt是Linux生态系统中用于虚拟化的核心工具。 作为最终用户,我正在使用这些工具来创建和运行虚拟机。 我以普通用户身份运行此工具,而没有使用root用户这样的特权用户,但是每次我尝试运行这些工具时,都要求输入sudo密码。 一段时间后,这成为一场噩梦。 是否有任何解决方案可以运行这些工具而无需在虚拟化方面输入密码和更改任何权限。 是。

波尔基特 (Polkit)

PolicyKit or simply Polkit is a component used to controlling system wide privileges in Unix and Linux operating systems. Fedora Linux distribution heavily uses Polkit. We will use Polkit to authenticate our self and start virt-manager without password.

PolicyKit或简称Polkit是用于控制Unix和Linux操作系统中的系统范围特权的组件。 Fedora Linux发行版大量使用Polkit。 我们将使用Polkit来验证自己的身份,并无需密码即可启动virt-manager。

创建虚拟化组 (Create Group For Virtualization)

To run virtualization services and software we need a group which have right to access related system resources. Most of the operating systems create this group as libvirt . If not create the group with the following command. But keep in mind this needs root privileges.

要运行虚拟化服务和软件,我们需要一个有权访问相关系统资源的小组。 大多数操作系统将此组创建为libvirt 。 如果没有,请使用以下命令创建组。 但是请记住,这需要root特权。

$ groupadd libvirt

将用户放入虚拟化组 (Put User To Virtualization Group)

Now we need to put our normal or current user to the virtualization group. As stated previous step the group name is libvirt but if it is different please change accordingly. In this command we added secondary group named libvirt to the user john

现在,我们需要将普通用户或当前用户加入虚拟化小组。 如上一步所述,组名称为libvirt但如果不同,请进行相应更改。 在此命令中,我们向用户john添加了名为libvirt辅助组。

$ sudo usermod -a -G libvirt john

创建Polkit规则 (Create Polkit Rule)

We will create polkit rule by using libvirt group. Create a file like

我们将使用libvirt组创建polkit规则。 创建一个类似的文件

/etc/polkit-1/rules.d/80-libvirt.rules

And put following content to the file. This rule will give libvirt groups users access to the virtualization capabilities without password.

并将以下内容放入文件中。 此规则将使libvirt组用户无需密码即可访问虚拟化功能。

polkit.addRule(function(action, subject) {
 if (action.id == "org.libvirt.unix.manage" && subject.local && subject.active && subject.isInGroup("libvirt")) {
 return polkit.Result.YES;
 }
});
LEARN MORE  How To Crack Passwords with John The Ripper with GUI
了解更多信息如何使用带有GUI的John The Ripper破解密码

翻译自: https://www.poftut.com/use-virt-manager-libvirt-normal-user-without-root-privileges-without-asking-password/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值