Host virtual machines on Ubuntu with Virt Manager
If you have an Ubuntu Server and wish to run virtual machines on it with Virtual Machine Manager, you’ll need to set up SSH and Libvirtd. Here’s how to do it on your Ubuntu system.
Setting up passwordless SSH
One of the most important things before hosting VMs on your Ubuntu Server is to set up passwordless SSH. If you do not set up passwordless SSH, VirtManager will repeatedly ask you to enter your SSH password (which is annoying).
To enable passwordless SSH, ensure you have an OpenSSH server set up on Ubuntu Server. If not, use the command below to install the OpenSSH server on Ubuntu.
Note: you must also enable SSH on all Linux host machines.
You can set up OpenSSH on Ubuntu Server with:
sudo apt install openssh-server
After installing the OpenSSH server on Ubuntu Server, open up the configuration file in the Nano text editor.
sudo nano -w /etc/ssh/sshd_config
In the configuration file, locate “PubkeyAuthentication” and ensure it looks like the example below.
PubkeyAuthentication yes
Then, save the edits with Ctrl + O, exit with Ctrl + X, and run the command below to restart the server.
sudo systemctl restart sshd
Upon restarting the server, you head to the Linux PC(s) and open a terminal window. Then, generate your key with the command below. However, don’t enter a password for the key. LeaInstead, leave it blank (unless you want a password for the key).
ssh-keygen
After running the command above, you’ll need to use the ssh-copy-id command to transmit your SSH key credentials to the Ubuntu Server.
ssh-copy-id your-username-on-the-server@your-ubuntu-server-or-hostname
Once the key is transmitted, go back to the Ubuntu server, and re-open the SSH config file for editing.
sudo nano -w /etc/ssh/sshd_config
In the configuration file, find “PasswordAuthentication yes” and change it to “no.”
PasswordAuthentication no
Save your edits in Nano with Ctrl + O and exit with Ctrl + X. Then, restart the SSH server again to finalize the changes.
sudo systemctl restart sshd
Once the SSH server is restarted, passwordless SSH will be set up and ready to use.
Setting up the Libvirt Daemon on Ubuntu Server
Ubuntu server needs an installation of Libvirt Daemon to serve virtual machines with QEMU/KVM over the network. To install Libvirt Daemon, open a terminal window and enter the command below.
sudo apt install libvirt-daemon qemu-system libvirt-daemon-system
Once the packages are installed, your Ubuntu Server is ready to host virtual machines to Linux PCs running VirtManager.
Installing VirtManager on the client machine
Now that everything is set up on Ubuntu Server, you’ll need to install VirtManager on the Linux PC accessing the VMs. Open up a terminal window and install the software.
Ubuntu
sudo apt install virt-manager
Debian
sudo apt-get install virt-manager
Arch Linux
sudo pacman -S virt-manager
Fedora
sudo dnf install virt-manager
OpenSUSE
sudo zypper install virt-manager
Creating VMs
To create a VM remotely, you must first add a connection to the Ubuntu Server in Virt Manager. Here’s how to do it.
Step 1: Click on the “File” button, followed by “Add Connection…”
Step 2: In the “Add Connection” pop-up window, select the box “Connect to a remote host over SSH.” Then, enter your SSH username and the Ubuntu Server or hostname/LAN IP address.
Step 3: Click the “Connect” button to connect to the Ubuntu Server Hypervisor.
Step 4: After connecting, click the “+” button to create a new VM on the Ubuntu Server Hypervisor. Then, select “Network Install (HTTPS, HTTPS, or FTP)” and click “Forward.”
Step 5: Paste the URL to the Linux OS you are trying to install into the URL box. In this example, we’ll be using Fedora Workstation.
https://download.fedoraproject.org/pub/fedora/linux/releases/36/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-36-1.5.iso
Step 6: After adding the URL, allow VirtManager to detect the OS. If it can’t, uncheck “Automatically detect from the installation/media source” and enter the name of the OS.
Step 7: You’ll be asked to assign RAM and CPU cores on the next page. Set the memory and CPU resources as needed. Then, click the “Forward” button to continue.
Step 8: You’ll now need to create a new disk image. Find the “Create a disk image for the virtual machine” and change it from 20 GB. Or, leave it at 20 if you feel that is enough space.
Step 9: Name your OS by adding a name in the text box. Then, click the “Finish” button to finish up.
Step 10: Start the VM by selecting it, clicking the play button, and selecting “Open.”