1

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?

Will
  • 2,292
arpho
  • 881
  • This is probably sudo not importing DISPLAY 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:28
  • 1
    The rationale for this default is that it is generally considered an avoidable security hazard to run GUI programs with root permissions. Of course gparted and synaptic really need root permissions. – HuHa Oct 30 '21 at 23:31
  • 1
    No one ever should run graphical applications with sudo 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:03
  • "Nobody ever" is one of those fundamentalist nonsense pragmas that drives me up the walls. How do you expect users to use synaptic, gparted, qdirstat? They all need root permissions to be useful. This attitude is what makes users go "screw those security dudes, they make the system completely unusable!" and use relaxed security settings for everything. – HuHa Oct 31 '21 at 15:57
  • Alternatives to gksu are developed in order to increase the security. Synaptic and Gparted work with pkexec, that applies PolicyKit. I don't know about Double Commander, maybe it still needs sudo -H. – sudodus Nov 01 '21 at 04:59

1 Answers1

4

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,

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.

sudodus
  • 46,324
  • 5
  • 88
  • 152
  • pkexec synaptic does not work, the same for pkexec gparted – arpho Nov 01 '21 at 08:23
  • @arpho, pkexec works for me with synaptic and gparted. 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
  • for synaptic synaptic-pkexec – nobody Nov 01 '21 at 09:52
  • @arpho, use what works for you, maybe it is necessary to switch session from Wayland to X and/or use xhost and sudo -H. This link (written 2017 and slightly modified after that) shows details of some methods. – sudodus Nov 01 '21 at 12:06