The easiest method to access virtual machine consoles is the program called virt-manager
. It is a GUI program that is an "all in one" solution to manage virtual machines in general - create, modify, start/stop them etc.
You may have virt-manager
already installed on your server as a part of KVM installation. If not, install it as you usual install any software, using the command
sudo apt install virt-manager
You should run virt-manager
with root privileges (otherwise it may have trouble communicating with libvirtd
daemon on your machine), ie.
sudo -b virt-manager
(the -b
parameter to sudo
tells to run the program in background - as GUI programs are usually run - to avoid blocking the terminal).
The program is basically self-explanatory and you can easily access the VM console with it.
However, because it is a GUI program, the tricky part is how to get it running on a remote server that you access via SSH (I suppose so, because you didn't specify exactly how do you access the server).
Running a GUI program on a remote server requires two things:
- an X server running on the local machine (from which you SSH to the server), to be able to display the GUI, and
- configured X forwarding over SSH between remote and local machine.
As for 2), you need to edit the file /etc/ssh/sshd_config
on your server and check if it contains a line that says
X11Forwarding yes
It usually doesn't, so you have to add that line and save the modified file (note: you must do it as root, eg. use sudo
to call your preferred editor on the file). After this, you need to restart the ssh service:
sudo service ssh restart
As for 1) the easiest case is when your local machine is also a Linux machine, as it already has a X server running to operate its local GUI :). In that case you don't need to do anything special besides adding a -X
parameter to ssh
command when you connect to the server:
ssh -X youruser@yourserver
The -X
parameter tells ssh
to forward the GUI over SSH to the local X server, so the program running on server will display its GUI on your local computer.
If your local machine is a Windows machine, then you need to install locally some software that provides the X server functionality (for example Xming). After X server is started, you need to tell your SSH client to forward the GUI. The exact way how to do it depends on the SSH client you use.
If you are using the built-in ssh
command in Windows 10/11, it should support the -X
option similarly to the Linux one (but I haven't tested it).
If you are using PuTTY (which is probably the most popular SSH client for Windows), before opening the connection you should go to Connection -> SSH (click "+" to expand) -> X11 in the options screen, and then tick the check box "Enable X11 forwarding" - this is equivalent to specify the -X
parameter in ssh
command (I have tested it and can confirm it works).
Below you can see a screenshot of virt-manager
accessing a VM console on the server (the server in this case is CentOS, the local machine is a quite old version of Ubuntu, the VM is OpenWRT :)) :
