CentOS 7 virt-manager “authentication failed”错误及解决方法

这两天在捣鼓CentOS 7,因为之前是在Debian用KVM,于是这次照着之前的做法来一步步安装KVM,然而最后打算用virt-manager来管理的时候,发现被拒之门外了。

virt-manager error

Unable to connect to libvirt.
authentication failed: no agent is available to authenticate.

呃,真够磨人的。看着像是权限问题。尝试了下,发现root级别的qemu:///system 是出错的,不过用户级别的qemu:///session 没有问题。因为默认是以非root用户执行virt-manager的,应该是这个原因导致权限的问题。

用户级别的权限受到很多限制,要全面发挥KVM的功能还是需要root级别。不过,现在却被挡在了门外。我先是检查了各种包有没有安装,结果是该装的都装了。

又看了下libvirtd服务的状态,一样:

$ service libvirtd status
Jan 06 02:55:16 - libvirtd[1195]: libvirt version: 1.2.17, package: 13.el7_2.2 (CentOS BuildSystem <http://bugs.centos.org>, 2015-12-09-13:08:22, worker1.bsys.centos.org)
Jan 06 02:55:16 - libvirtd[1195]: authentication failed: no agent is available to authenticate
Jan 06 02:55:16 - libvirtd[1195]: End of file while reading data: Input/output error

然后又Google了下,网上很多CentOS教程第一步就是说禁用SELinux,不过CentOS官方Wiki没有提这点。而且我没有打算把虚拟机放到默认路径之外,应该不是SELinux的问题。

最后在Red Hat的邮件列表搜到一篇,提到有关“no agent is available to authenticate”错误以及解决方法 ( https://www.redhat.com/archives/libvir-list/2015-June/msg00583.html )。照着这封邮件第二个链接 https://fedorapeople.org/groups/docs/cookbook/#access-to-libvirt-without-root-privileges ) 中的方法做了后,最终解决了我的非root用户运行virt-manager时的问题。

下面为概括说明
1、为libvirt添加一条polkit策略

vi /etc/polkit-1/localauthority/50-local.d/50-org.libvirt-group-access.pkla

内容为:

[libvirt group Management Access]
Identity=unix-group:libvirt
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes

2、创建libvirt组,将需要用于管理的非root用户添加到libvirt组。

groupadd libvirt
usermod -a -G libvirt user_name 

至此,问题解决。


参考:
https://www.redhat.com/archives/libvir-list/2015-June/msg00583.html
https://fedorapeople.org/groups/docs/cookbook/#access-to-libvirt-without-root-privileges

4 thoughts on “CentOS 7 virt-manager “authentication failed”错误及解决方法”

Leave a Reply to Jack Cancel reply

Your email address will not be published. Required fields are marked *