Passing mouse, keyboard input to Incus container with desktop environment

I’m running an Ubuntu 22.04 container in Incus. So far, I have enabled an x11 server and am running an Xfce desktop. I have accessed it through VNC. The mouse pointer moves, but I cannot click and keyboard input does not work.

Can anyone help me to pass the right devices/give the right permissions?

Here’s a part of my config:

config:
...
  raw.lxc: lxc.cgroup2.devices.allow = c 13:* rwm
  security.nesting: "true"
  security.privileged: "true"
...
devices:
  enp0s3:
    name: eth1
    nictype: macvlan
    parent: enp0s3
    type: nic
  fuse:
    path: /dev/fuse
    required: "true"
    source: /dev/fuse
    type: unix-char
  gpu:
    path: /dev/dri/card0
    source: /dev/dri/card0
    type: unix-char
  input0:
    path: /dev/input/event0
    source: /dev/input/event0
    type: unix-char
  mouse0:
    path: /dev/input/mouse0
    source: /dev/input/mouse0
    type: unix-char
  renderD128:
    path: /dev/dri/renderD128
    source: /dev/dri/renderD128
    type: unix-char
  uinput:
    path: /dev/uinput
    required: "true"
    source: /dev/uinput
    type: unix-char

I’m honestly loading as many devices as I can just to see which one will work until I can narrow down what exactly is necessary.

The end goal is to be able to run several containers that can play games (emulators, Steam) and use Sunshine/Moonlight to stream to clients. I prefer containers over VMs because it allows the use of a single GPU for several clients. Right now, I am testing without GPU because my GPU server is down for a few days.

Welcome!

There are already several tutorials on how to GUI apps in system containers. I would suggest to consult them. Doing this through VNC for games may be painful. But if you insist, then you would just need X11 forwarding when you SSH to the system container. It’s a parameter in SSH to forward for you the Unix socket for the X server. Then, you run an X11 app in the container and you get the output on your desktop.

An improvement is to setup X2Go. With this you you will get a whole desktop session in the container, and on your desktop you would get a window of that desktop session. Really cool, download:start [X2Go - everywhere@home]

If you want to do this with GPU acceleration and run games decently, see this guide, Incus / LXD profile for GUI apps: Wayland, X11 and Pulseaudio

From what you said, I guess you only want gui running in instances, and access them through vnc/rdp/Sunshine/Moonlight.
If so, you don’t need to pass devices to instances. Because X11 will always provides virtual mouse and keyboard for you. You can try DISPLAY=:0 xinput list to see them. And I have a vnc instance which doesn’t have any mouse or keyboard attach to it, and I can use mouse and keyboard through vnc.
Most likely it’s a vnc problem:
https://superuser.com/questions/682287/vnc-console-does-not-accept-any-keyboard-mouse-inputs
https://superuser.com/questions/1403291/tightvnc-server-running-on-windows-10-ignores-mouse-and-keyboard-inputs-from-ti
https://forums.raspberrypi.com/viewtopic.php?t=350073

I don’t think it’s a dependency problem, normally everything needed was installed when installing Xfce. But you can try install xserver-xorg-input-mouse for ps2 mouse which is the default virtual mouse.

If it’s a x11 problem, you can find it in x11’s log.

There is one more possible problem. It’s happens when you have a custom x11 config which you messed up. You can find it in x11’s log too.

This is an example of using X11 forwarding. Gets the job done, no acceleration. The next step up is to setup a VNC server in the container and connect with a VNC client. Then, all other methods up to using the GPU in the container and getting proper gameplay.

$ incus launch images:ubuntu/24.04/cloud x11
Launching x11
$ incus exec x11  -- passwd ubuntu
New password: 
Retype new password: 
passwd: password updated successfully
$ incus exec x11  -- apt install openssh-server x11-apps
...
$ incus list x11 -c ns4
+------+---------+---------------------+
| NAME |  STATE  |        IPV4         |
+------+---------+---------------------+
| x11  | RUNNING | 10.10.10.126 (eth0) |
+------+---------+---------------------+
$ ssh -X -o PreferredAuthentications=password -o PubkeyAuthentication=no ubuntu@10.10.10.126
ubuntu@10.10.10.126's password: 
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-60-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro
Last login: Thu Jun 26 12:41:07 2025 from 10.10.10.1
/usr/bin/xauth:  file /home/ubuntu/.Xauthority does not exist
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@x11:~$ xclock

There are quite a few guides how to archive what you want. Take a look at this example Linux Desktop Environments in an Incus Container Used it a few times and it always worked…

It all depends on your needs as mentioned above.