Sample Header Ad - 728x90

Allow Wayland access to Distrobox running as another user

3 votes
0 answers
79 views
This is certainly a niche use-case, so I ask you to bear with me. My goal is to run a proprietary application within Distrobox. I don't want to expose my local username (reused online) to said application, hence I'm trying to run this as a different local user. ### Starting point ### It's already possible to run application on host as different user, even if it's not the most secure method in the world, thanks to [this answer by Sam Mason](https://unix.stackexchange.com/a/791365/8305) . To summarize, assuming the secondary, non-session username is other, you need to do the following:
$ sudo chown :other "$XDG_RUNTIME_DIR" "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
$ chmod g+rwx "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
$ chmod g+x "$XDG_RUNTIME_DIR"
$ machinectl shell \
  --setenv=WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" \
  --setenv=XDG_SESSION_TYPE \
  other@
And with just that, you can run any Wayland application within the context of the other user in your current session. ### XWayland works too ### With a few additions to the above method, you can get X applications (such as Steam and myriad other Electron crapware) to run as the other user:
$ xhost +local:
$ machinectl shell \
  --setenv=WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" \
  --setenv=XDG_SESSION_TYPE \
  --setenv=DISPLAY \
  other@
**Disclaimer** I don't understand the security implications of xhost (or assigning those permissions to the $WAYLAND_DISPLAY) and if there are safer alternatives, whether better permissions or different method entirely. If you want to use this method, do so at your own risk. The xhost command is a suggestion from [this guide](https://www.siberoloji.com/how-to-use-distrobox-for-containerized-apps-on-arch-linux/#7-running-gui-applications-from-the-container) . ### The problem with Wayland in another user's Distrobox ### As I mentioned above, using this method applications run perfectly fine whether Wayland or XWayland. When it comes to Distrobox, however, only the X applications run fine. Any Wayland application within Distrobox (and running as different user) refuses to start and always crashes with some variant of unable to open display errors. How do I go about debugging this issue? How come passing DISPLAY work perfectly, but fail with WAYLAND_DISPLAY? Any hint would be appreciated. As I mentioned before, this is a niche edge case. I don't expect solutions outright, Just showing me potential path forward would be much appreciated. **PS** As an aside, theoretically there might be a way to accomplish my original goal (not exposing my local username to Distrobox) without going through such rigmarole. When initializing a Distrobox container, it [actually creates an user](https://distrobox.it/usage/distrobox-init/) within it with the same name as the local username and assigns the same UID and GID. If Distrobox would just let the username variable to be set manually, it'd probably do exactly what I want... It's as frustrating as you might imagine. I asked if there's anyway for me to modify it on [GitHub issues](https://github.com/89luca89/distrobox/issues/1783) , but I'm suffering in silence.
Asked by Oxwivi (1792 rep)
Jul 6, 2025, 07:03 PM
Last activity: Jul 12, 2025, 11:50 AM