Thomas Mullaly

DevOps, Security and IT Leadership

Connect Foreman to Kvm Host Machine

We need to setup ssh keys so that the foreman vm can communicate with the host operating system. Becasue we’re running Ubuntu, the root account is disabled by default so I’m going to enable it by giving it a password. Then we’re going to create an ssh key on the foreman vm and transfer it to the kvm host. We’ll test the ssh key and then we’ll use the foremen web interface to add the ability to provision a kvm instance.

First log into the kvm host machine and sudo to root (sudo -i). Create a password for root:

passwd root

Now, let’s enable the ability of root to login via ssh

vi /etc/ssh/sshd_config


PermitRootLogin without-password


PermitRootLogin yes

Now restart sshd:

service ssh restart

Let’s log into the foreman virtual machine and set up the ssh keys.

root# mkdir /usr/share/foreman/.ssh
root# chmod 700 /usr/share/foreman/.ssh
root# chown foreman:foreman /usr/share/foreman/.ssh
root# su foreman -s /bin/bash
foreman$ ssh-keygen
foreman$ ssh-copy-id
foreman$ ssh

Test the connection:

virsh -c qemu+ssh:// list

Now go to the foreman web application:

Infrastructure -> Compute Resources -> New Compute Resource

Name: KVM-Host

Provider: Libvirt

URL: qemu+ssh://

Display type: VNC

Console: Checked (yes)

Test the connection and if it works then hit Submit.

Now we can provision a new KVM guest through foreman.