18.2. Remote Management with SSH
sshpackage provides an encrypted network protocol that can securely send management functions to remote virtualization servers. The method described below uses the
libvirtmanagement connection, securely tunneled over an SSH connection, to manage the remote machines. All the authentication is done using SSH public key cryptography and passwords or passphrases gathered by your local SSH agent. In addition, the VNC console for each guest is tunneled over SSH.
- You require root log in access to the remote machine for managing virtual machines.
- The initial connection setup process may be slow.
- There is no standard or trivial way to revoke a user's key on all hosts or guests.
- SSH does not scale well with larger numbers of remote machines.
The following instructions assume you are starting from scratch and do not already have SSH keys set up. If you have SSH keys set up and copied to the other systems, you can skip this procedure.
virt-managermust be run by the user who owns the keys to connect to the remote host. That means, if the remote systems are managed by a non-root user,
virt-managermust be run in unprivileged mode. If the remote systems are managed by the local root user, then the SSH keys must be owned and created by root.
Optional: Changing userChange user, if required. This example uses the local root user for remotely managing the other hosts and the local host.
Generating the SSH key pairGenerate a public key pair on the machine where
virt-manageris used. This example uses the default key location, in the
ssh-keygen -t rsa
Copying the keys to the remote hostsRemote login without a password, or with a pass-phrase, requires an SSH key to be distributed to the systems being managed. Use the
ssh-copy-idcommand to copy the key to root user at the system address provided (in the example,
ssh-copy-id -i ~/.ssh/id_rsa.pub firstname.lastname@example.org@host2.example.com's password:Afterwards, try logging into the machine and check the
.ssh/authorized_keysfile to make sure unexpected keys have not been added:
ssh email@example.comRepeat for other systems, as required.
Optional: Add the passphrase to the ssh-agentAdd the pass-phrase for the SSH key to the
ssh-agent, if required. On the local host, use the following command to add the pass-phrase (if there was one) to enable password-less login.
ssh-add ~/.ssh/id_rsaThis command will fail to run if the ssh-agent is not running. To avoid errors or conflicts, make sure that your SSH parameters are set correctly. See the Red Hat Enterprise System Administration Guide for more information.
libvirt daemon provides an interface for managing virtual machines. You must have the
libvirtd daemon installed and running on every remote host that you intend to manage this way.
# systemctl enable libvirtd.service
# systemctl start libvirtd.service
libvirtdand SSH are configured, you should be able to remotely access and manage your virtual machines. You should also be able to access your guests with
VNCat this point.
Remote hosts can be managed with the virt-manager GUI tool. SSH keys must belong to the user executing virt-manager for password-less login to work.
- Start virt-manager.
- Open the File ⇒ Add Connection menu.
Figure 18.1. Add connection menu
- Use the drop down menu to select hypervisor type, and click the Connect to remote host check box to open the Connection Method (in this case Remote tunnel over SSH), enter the User name and Hostname, then click Connect.