1

Could anybody help me debug the following issue: I have a menu shortcut that starts up gnome-terminal as root. The shortcut refers to the following .desktop file:

[Desktop Entry]
Name=Root Terminal
Exec=/usr/local/bin/root-term
Comment=Root Terminal
Terminal=false
Icon=org.gnome.Terminal
Type=Application

The script /usr/local/bin/root-term is basically one command (it didn't work properly when I tried to put the command directly into the .desktop file, hence the separate script):

#!/bin/bash
pkexec env SSH_AUTH_SOCK=$SSH_AUTH_SOCK DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gnome-terminal

This worked perfectly until now. Since few days, after some update (however I don't know which one) the first time I click this menu shortcut, pkexec's password prompt pops up and after I enter the password I have to wait several seconds until the terminal window appears.

This happens only when the script is run the first time after the machine is booted. On subsequent clicks on this menu item, the terminal window appears instantly after answering the password prompt.

I don't even know where to start looking for. Any ideas? Ubuntu 20.04.

4
  • Try gksudo instead of pkexec also disable the pkexec. Jan 26, 2023 at 19:00
  • gksudo is not present on my system, even no candidate to install is prompted when I type gksudo.
    – raj
    Jan 27, 2023 at 11:08
  • I simply run sudo whatevercommand in a normal gnome-terminal window and it works as before also in an up to date version of Ubuntu 22.04.x LTS. I don't see why you want a separate desktop entry for gnome-terminal as root.
    – sudodus
    Jan 28, 2023 at 14:23
  • @sudodus Simply a matter of convenience. If I want to do something as root, it's usually something more than just a single command. In that case I just prefer to have a clearly separated terminal window where I can work as root. I'm just used to working that way and I don't see any reason to change the way of working that is convenient and effective for me.
    – raj
    Jan 28, 2023 at 18:43

2 Answers 2

2
+25

Desktop file for Root Terminal

The following desktop file works for me (when located in /usr/share/applications/) in current 20.04.x and 22.04.x,

[Desktop Entry]
Version=1.0
Name=Root Terminal
Exec=gnome-terminal --title='Root Terminal' -- sudo -i
Comment=Root Terminal
Terminal=false
Icon=org.gnome.Terminal
Type=Application

You may want to use sudo -iH, but if I understand correctly, -H is no longer necessary to protect graphical applications, that can be run both with and without elevated permissions.

Edit: gvfs admin backend

The gvfs admin backend is a good tool 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

In theory, the gvfs admin backend method (which uses polkit) 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.

13
  • While this works, it does not fully solve my problem. The actual problem is some unexplainable delay the first time pkexec is started (that previously didn't occur). I want to find the root cause of this problem and solve it, because I have also other similar shortcuts that call some specific programs as root (for example gedit to edit a particular file) and your method cannot be used in that case.
    – raj
    Jan 28, 2023 at 21:37
  • I see. Then I suggest to try the gvfs admin backend with gedit. See the edited answer. I don't know if it works with all the tools that you want to use with pkexec, and I don't know if the gvfs admin backend is affected by the delay ...
    – sudodus
    Jan 28, 2023 at 22:23
  • That still can be considered only a workaround, not a solution. It's better than nothing, but I look for a solution.
    – raj
    Jan 29, 2023 at 18:06
  • Have you tested in an up to date [persistent] live system (20.04.x LTS and/or 22.04.x LTS) if your desktop files and associated shellscripts work as intended (without a delay)? In that case there is probably something specific in your current operating system, that causes the problem.
    – sudodus
    Jan 29, 2023 at 18:45
  • 1
    I finally got some time to investigate this and strace showed that the problem is somewhere within GNOME itself, pkexec is not at fault. gnome-terminal and gedit exhibit identical delay when eg. started for the first time from root shell obtained by sudo. strace shows timeouts when trying to get data from some service (the pattern is identical with both programs), but I'm unable to analyze it further.
    – raj
    Feb 22, 2023 at 23:11
1

Had basically the same issue: (20.04) using pkexec in a .desktop file to open a program that would delay on first launch for ~20 seconds.

In my case, it was caused by a bug with xdg-desktop-portal:
https://bugs.launchpad.net/ubuntu/+source/xdg-desktop-portal/+bug/1878081

Other users have reported it safe to uninstall, which fixed it for me:

sudo apt remove xdg-desktop-portal
3
  • The description of xdg-desktop-portal package says that it is used to allow snap applications eg. open files outside the sandbox. As I use Chromium which is distributed as snap only, I'll probably need it, so won't uninstall it. However, it is probably the root cause as the delay looks very similar to delay when starting snap applications. Thanks for the info and link to the bug!
    – raj
    Mar 30, 2023 at 21:53
  • Instead of uninstalling, I managed to find in the net the previous version of the xdg-desktop-portal package, 1.6.0-1ubuntu1 (current one is 1.6.0-1ubuntu2) and downgraded. Can confirm that after downgrade the problem disappeared.
    – raj
    Mar 30, 2023 at 22:15
  • Np! Thanks for finding a cleaner solution.
    – Mdurks
    Mar 31, 2023 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .