Running GUI applications as root
Circumvent running graphical apps as root
To edit files as root, use sudoedit.
$ nautilus admin:///root/
$ gedit admin:///etc/fstab
Ctrl+land then prepend the
admin://scheme to the resource path. The same effect can be attained via the Other locations server address bar.
By default, and for security reasons, root will be unable to connect to a non-root user's X server. There are multiple ways of allowing root to do so however, if necessary.
The proper, recommended way to run GUI apps under X with elevated privileges is to create a Polkit policy, as shown in this forum post. This should however "only be used for legacy programs", as reminds. Applications should rather "defer the privileged operations to an auditable, self-contained, minimal piece of code that gets executed after doing a privilege escalation, and gets dropped when not needed". This may be the object of a bug report to the upstream project.
Those methods wrap the application in an elevation framework and drop the acquired privileges once it exits:
$ kdesu application
$ sudo application
- AUR (wrapper around su which will transfer your X credentials)
$ sux root application
These methods will allow root to connect to a non-root user's X server, but present varying levels of security risks, especially if you run ssh. If you are behind a firewall, you may consider them to be safe enough for your requirements.
Xhost can be used to temporarily allow root access.
Permanently allow root access
- Method 1: Add the line
session optional pam_xauth.so
/etc/pam.d/su-l. Then switch to your root user using
- Method 2: Globally in
Add the following line to
This will permanently allow root to connect to a non-root user's X server.
Or, merely specify a particular app:
appname is the name of the particular app. (e.g. kwrite)
$ sudo gedit No protocol specified Unable to init server: Could not connect: Connection refused (gedit:2349): Gtk-WARNING **: cannot open display: :0
Before Wayland, running GUI applications with elevated privileges could be properly implemented by creating a Polkit policy, or more dangerously done by running the command in a terminal by prepending the command with
sudo; but under (X)Wayland this does not work anymore as the default has been made to only allow the user who started the X server to connect clients to it (see the bug report and the upstream commits it refers to).
Avoid running graphical applications as root if possible, see #Circumvent running graphical apps as root.
A more versatile though more insecure workaround allows any graphical application to be run as root #Using xhost.
A more versatile —though much less secure— workaround is to use xhost to temporarily allow the root user to access the local user's X session. To do so, execute the following command as the current (unprivileged) user:
$ xhost si:localuser:root
To remove this access after the application has been closed:
$ xhost -si:localuser:root