How to enable KVM virsh console access for Ubuntu Linux VM

Posted on in Categories , , last updated February 19, 2017

I just followed your tutorial and setup KVM with Ubuntu Linux as a new guest virtual machine. However, I am unable to use the command: ‘virsh console vm’. How do I setup and enable console access in order to gain shell access on the newly created Ubuntu Linux 16.04 LTS VM?

Activating the serial console in the Ubuntu Linux 16.04 LTS guest is an excellent way to log in and solve problems.

Our sample setup

  1. KVM host IP:
  2. KVM guest OS: Ubuntu Linux 16.04 LTS
  3. KVM guest IP:
  4. KVM guest name: ubuntu-box1
  5. KVM guest user name: vivek
  6. KVM guest password: hidden-secrete

How do I setup console access of Ubuntu 16.04 KVM Guest

First, you need to login using ssh or VNC client to your Ubuntu guest.

Use ssh login

In this example, I am login using ssh client from my workstation (or type command on KVM host itself) to the Ubuntu Linux VM guest:
$ ssh vivek@
After log in gain access to the root shell:
$ sudo -s

Use vnc login

Type the following command on your KVM host:
$ virsh dumpxml ubuntu-box1 | grep vnc
<graphics type='vnc' port='5901' autoport='yes' listen=''>

Please note down the port value (i.e. 5901). You need to use an SSH client to setup tunnel and a VNC client to access the remote vnc server. Type the following SSH port forwarding command from your Linux/Unix/MacOS client or desktop system:
$ ssh {user}@{KVM-host-IP-here} -L 5901:
$ ssh vivek@ -L 5901:

Once you have ssh tunnel established, you can point your VNC client at your own IP (localhost) address and port 5901 as follows in VNC client:

Fig.01: Graphical VNC client to connect to Ubuntu Linux 16.04 LTS server console
Fig.01: Graphical VNC client to connect to Ubuntu Linux 16.04 LTS server console

Log in to your VM:
Fig.02: Login to my Ubuntu guest VM
Fig.02: Login to my Ubuntu guest VM

Configure a serial console in the Ubuntu guest

Finally type the following two commands to enable a serial console in the guest to access a connection using ‘virsh console’ command:
$ sudo systemctl enable serial-getty@ttyS0.service
$ sudo systemctl start serial-getty@ttyS0.service

Sample outputs:

Created symlink from /etc/systemd/system/ to /lib/systemd/system/serial-getty@.service.

How do I access console of Ubuntu 16.04 KVM Guest from KVM host

To see a list of running VM, enter:
$ virsh list
Sample outputs:

 Id    Name                           State
 1     freebsd                        running
 2     ubuntu-box1                    running
 3     ubuntu-box2                    running

Type the following command from KVM host to login to the guest named ubuntu-box1
$ virsh console ubuntu-box1
$ virsh console 2
Sample session:

Animated gif 01: virsh console demo
Animated gif 01: virsh console demo

Use Ctrl + ]to exit the console.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 2 comments/add one below):

2 comment

    Have a question? Post it on our forum!