系统环境:CentOS Linux release 7.5.1804 (Core)
虚拟化:libvirt 3.9.0 版本
操作之前必须搞清楚:
1、 服务端 webvirtmgr 的管理用户是谁?
ps -ef|grep webvirtmgr #官方一般建议是nginx
2、 客户端 libvirt 的管理用户是谁?
通过webvirtmgr管理界面上SSH登录时所输入的用户名
如:webvirtmgr
1、 在webvirtmgr服务器(服务端)生成密钥
#创建nginx宿主目录
cd /home
mkdir nginx #因为nginx用户在创建的时候是设置的sbin/nologin 所以这里需要手动创建家目录
chown nginx.nginx nginx/
chmod 700 nginx/ -R
#切换到nginx用户下生成秘钥对
su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen ---期间输入yes后直接回车,回车
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ chmod 0600 ~/.ssh/config
2、 在kvm(受控端)服务器上配置webvirt用户
[root@kvm_10 home] useradd webvirtmgr
[root@kvm_10 home] echo "123456" | passwd --stdin webvirtmgr
[root@kvm_10 home] groupadd libvirt
[root@kvm_10 home] usermod -G libvirt -a webvirtmgr
3、 在webvirtmgr服务器(服务端)上,将ssh-key上传到kvm服务器上
su - nginx -s /bin/bash
-bash-4.2$ ssh-copy-id [email protected]
4、 在kvm(受控端)服务器上配置 libvirt ssh授权
vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:webvirtmgr
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
#重启 libvirtd 服务
systemctl restart libvirtd
5、 webvirtmgr 控制台中添加主机