Skip to content

Instantly share code, notes, and snippets.

@davesilva
Created August 14, 2020 11:50
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save davesilva/da709c6f6862d5e43ae9a86278f79188 to your computer and use it in GitHub Desktop.
Save davesilva/da709c6f6862d5e43ae9a86278f79188 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.

@zarinfam
Copy link

zarinfam commented Mar 13, 2023

Thanks, It helped me a lot.

@dhavlik
Copy link

dhavlik commented Apr 20, 2023

Thanks! Huge help here.

@ChangHoon-Sung
Copy link

It works perfectly! Thanks a lot.

@wzhpro
Copy link

wzhpro commented Sep 26, 2023

Why virt-manager auth failed without ask passwords

Permission denied, please try again.
Received disconnect from 10.8.8.194 port 22:2: Too many authentication failures
Disconnected from 10.8.8.194 port 22: Input/output error

Verify that the 'libvirtd' daemon is running on the remote host.

@eugenefvdm
Copy link

eugenefvdm commented Oct 12, 2023

Thank you! This works on my Mac M2. I can finally access VMs in our data centre using a Mac. This is such a relief.

All problem I'm experiencing is I can't connect to the graphical consoles.

I get the standard:

Connecting to graphical console for guest

and nothing happens.

I would like to hear if other people are able to access their graphical consoles...

Edit: I closed the application and tried again, and now all VMs are opening graphically!! :-)

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