Skip to content

Instantly share code, notes, and snippets.

@jpuskar
Forked from davesilva/virt-manager-macos.md
Created November 13, 2023 15:15
Show Gist options
  • Save jpuskar/0f6024e6a3f8d60d33b72f9721c64e7a to your computer and use it in GitHub Desktop.
Save jpuskar/0f6024e6a3f8d60d33b72f9721c64e7a to your computer and use it in GitHub Desktop.
Remote virt-manager from Mac OS

If you have a Linux machine with KVM on it, you can manage those VMs remotely from a Mac using virt-manager.

Step 1: Allow your user non-root access to KVM

SSH to the Linux machine and add your SSH user to the libvirt group

sudo usermod -a -G libvirt $(whoami)

Running id $(whoami) should list the libvirt group. You may also need to edit /etc/libvirt/libvirtd.conf to ensure that the socket has the right owner and permissions. Make sure you have these lines in there:

unix_sock_group = "libvirt"
unix_sock_rw_perms = "0770"

you should now be able to manage your VMs from the Linux machine without root access. If you open virt-manager locally on the Linux machine (assuming it's not headless) you will no longer be prompted to enter your password.

Step 2: Install virt-manager for Mac OS

Homebrew recipe for virt-manager

As stated in the readme, you can install it using

brew tap jeffreywildman/homebrew-virt-manager
brew install virt-manager virt-viewer

Step 3: Connect virt-manager to the Linux machine over SSH

First you need to ensure that you're using an SSH key rather than a password to log into the Linux machine. If you connect over ssh without specifying a password then you should be good.

If you try to tell virt-manager to connect over SSH by just specifying the hostname it might not work though. You'll see an error like End of file while reading data: nc: unix connect failed: No such file or directory: Input/output error. The file it's referring to is the libvirtd socket and the reason it can't find it is because it's looking in the wrong place. It's looking for the sock file in /usr/local/lib but it actually lives at /var/run/libvirt/libvirt-sock (at least it does on Debian). Luckily there's a query param you can pass in the SSH URL to override the socket location:

virt-manager --connect="qemu+ssh://USER@HOSTNAME/system?socket=/var/run/libvirt/libvirt-sock"

That should allow virt-manager to connect and let you manage your VMs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment