Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2018 11:46
What would you like to do?
Run a graphical application as root via sudo in a Wayland session
#!/usr/bin/env bash
# Enable root access to x-windows system.
# Motivation: Trying to run a graphical application as root via su, sudo in a
# Wayland session (e.g. GParted or Gedit), will fail. Apps which use polkit to
# request administrator permissions for just certain operations and only when
# needed are not affected (they are not started as root right away).
# [1]
# Based on a Reddit comment.
# [2]
if (( $# != 1 )); then
echo "Illegal number of parameters."
echo "Usage: wsudo [command]"
exit 1
for cmd in sudo xhost; do
if ! type -P $cmd &>/dev/null; then
echo "$cmd it's not installed. Aborting." >&2
exit 1
xhost +SI:localuser:root
sudo $1
#disable root access after application terminates
xhost -SI:localuser:root
#print access status to allow verification that root access was removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment