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

Change:

PermitRootLogin without-password

to

PermitRootLogin yes

Now restart sshd:

service ssh restart

Let’s log into the foreman virtual machine and set up the ssh keys. http://theforeman.org/manuals/1.6/index.html#5.2.5LibvirtNotes

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 root@hostname.com
foreman$ ssh root@hostname.com
exit

Test the connection:

virsh -c qemu+ssh://kvm.thunderhouse.com/system list

Now go to the foreman web application:

Infrastructure -> Compute Resources -> New Compute Resource

Name: KVM-Host

Provider: Libvirt

URL: qemu+ssh://root@kvm.thunderhouse.com/system

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.