If I launch Thunar from the command line it works, but if I try to launch Thunar using sudo, only the icon on the status bar shows up but no window; the same problem happens with gparted, synaptic and double commander, what is wrong?
1 Answers
gvfs admin backend - for elevated permissions with GUI tools
In Ubuntu 17.10 (gvfs >= 1.29.4) and newer versions you can use the gvfs admin backend. Notice that you need the full path, for example
thunar admin:///path/to/directory
gedit admin:///path/to/file
so if you want to manage your /etc
directory, you can use
thunar admin:///etc
In theory, the gvfs admin backend method (which uses PolicyKit) is better and safer (than xhost
and sudo -H
), regardless of the UI you use.
You don't run the whole application as root. Privilege escalation happens only when strictly necessary. See the following link and links from it,
sisco311's reply in the Ubuntu Forums thread 'Which best practice for using gedit as root?'
This is post #4. See also post #6 in the same thread.
pkexec
Alternatives to gksu
are developed in order to increase the security. Synaptic and Gparted work with pkexec
(another PolicyKit application). See man pkexec
.
You can run from a terminal window
pkexec synaptic
pkexec gparted
but the execution using PolicyKit is built into the graphical launch mechanism, so that you see only the pop up window asking for password.
But command line tools (in terminal windows) and sudo
are often recommended when elevated permissions are necessary. A file browser open with elevated permissions makes it easy to damage the operating system by mistake.

- 46,324
- 5
- 88
- 152
-
-
@arpho,
pkexec
works for me withsynaptic
andgparted
. It works for me in Ubuntu 20.04.3 LTS both in X and Wayland sessions. Which flavour (maybe Xubuntu because you ask about Thunar) and which version are you running ( other than 20.04.3 LTS)? Or some other flavour or version? Or maybe a non-Ubuntu distro? - If you let us know details about your operating system, it will be easier to help you. Otherwise there will only be general advice. – sudodus Nov 01 '21 at 09:37 -
-
@arpho, use what works for you, maybe it is necessary to switch session from Wayland to X and/or use
xhost
andsudo -H
. This link (written 2017 and slightly modified after that) shows details of some methods. – sudodus Nov 01 '21 at 12:06
sudo
not importingDISPLAY
from your environment. See also here: https://askubuntu.com/questions/175611/cannot-connect-to-x-server-when-running-app-with-sudo – HuHa Oct 30 '21 at 23:28sudo
ever. @HuHa the suggestions you provide are greatly outdated by now (e.g. gksudo is not anymore in the repos for years), and certainly will not work when running on Wayland (default again on Ubuntu 21.10) instead of Xorg – vanadium Oct 31 '21 at 13:03gksu
are developed in order to increase the security. Synaptic and Gparted work withpkexec
, that applies PolicyKit. I don't know about Double Commander, maybe it still needssudo -H
. – sudodus Nov 01 '21 at 04:59