Running GUI applications as root

From ArchWiki
Revision as of 07:33, 31 January 2018 by PXf (talk | contribs) (Ponctual methods: Wrong spelling: ponctual->punctual (A.K.A "instant"))
Jump to navigation Jump to search

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.

Warning: All of the following methods have security implications that users should be aware of. As put by Emmanuele Bassi, a GNOME developper: "there are no *real*, substantiated, technological reasons why anybody should run a GUI application as root. By running GUI applications as an admin user you're literally running millions of lines of code that have not been audited properly to run under elevated privileges; you're also running code that will touch files inside your $HOME and may change their ownership on the file system; connect, via IPC, to even more running code, etc. You're opening up a massive, gaping security hole [...]."[1]

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 pkexec(1) 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"[2]. This may be the object of a bug report to the upstream project.

Punctual methods

Those methods wrap the application in an elevation framework and drop the acquired privileges once it exits:

$ kdesu name-of-app

See also Sudo#kdesu.

Warning: gksu has been deprecated since 2011[3], and has not seen any update since 2014[4].
$ gksu name-of-app

See also Sudo#gksu.

$ bashrun --su name-of-app
  • sudo (must be installed and properly configured with visudo)
$ sudo name-of-app
  • suxAUR (wrapper around su which will transfer your X credentials)
$ sux root name-of-app

Alternate methods

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.

Temporarily allow root access

See Xhost.

Permanently allow root access

Method 1: Add the line

session optional

to /etc/pam.d/su and /etc/pam.d/su-l. Then switch to your root user using 'su' or 'su -'.

Method 2: Globally in /etc/profile

Add the following to /etc/profile

export XAUTHORITY=/home/non-root-usersname/.Xauthority

This will permanently allow root to connect to a non-root user's X server.

Or, merely specify a particular app:

export XAUTHORITY=/home/usersname/.Xauthority kwrite

(to allow root to access kwrite, for instance.)


If you are running wayland, you'll find that the fallback X server won't work when running programs as root. Try running xhost +local: first.