Sample Header Ad - 728x90

Run sudo Exec in .desktop via pkexec: Qt Error

0 votes
1 answer
602 views
I have a configuration in virtualbox that requires me to run the application with sudo privileges. I have been editing the .desktop file to run with sudo (note a simply changing the Exec variable to Exec=sudo virtualbox does not work even with the appropriate changes to the sudoers file): $ cat /usr/share/applications/virtualbox.desktop [Desktop Entry] Name=VirtualBox GenericName=PC virtualization solution Type=Application Exec=virtualbox %U TryExec=VirtualBox Keywords=virtualization; Keywords[de]=Virtualisierung; Keywords[ru]=виртуализация; MimeType=application/x-virtualbox-vbox;application/x-virtualbox-vbox-extpack;application/x-virtualbox-ovf;application/x-virtualbox-ova; Icon=virtualbox Categories=Emulator;System;Utility; Actions=RootManager;Manager Comment=Run several virtual systems on a single host computer Comment[de]=Mehrere virtuelle Maschinen auf einem einzigen Rechner ausführen Comment[it]=Esegui più macchine virtuali su un singolo computer Comment[ko]=가상 머신 Comment[pl]=Uruchamianie wielu systemów wirtualnych na jednym komputerze gospodarza Comment[ru]=Запуск нескольких виртуальных машин на одном компьютере Comment[sv]=Kör flera virtuella system på en enda värddator [Desktop Action Manager] Exec=virtualbox Name=Open Oracle VM Manager Name[de]=Oracle VM Manager öffnen [Desktop Action RootManager] Exec=gnome-terminal -e "bash -c 'sudo -i /usr/bin/virtualbox;'" Name=Open Manager as Admin The above works and is an ok workaround for the time being but notice that the authentication happens in the gnome-terminal. I would like to bypass this with pkexec (e.g. Exec=pkexec virtualbox) but I get the following error: ~$ pkexec virtualbox Qt WARNING: could not connect to display Qt FATAL: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb. Aborted (core dumped) I have identified some possible culprits/solutions: - https://askubuntu.com/questions/1041588/virtualbox-not-launching-on-ubuntu-18-04-qt-lib-problem - https://unix.stackexchange.com/questions/203136/how-do-i-run-gui-applications-as-root-by-using-pkexec I have a feeling my problem is not associated so much with the first link since the application works fine without the use of pkexec. The second link adds custom actions to the freedesktop policykit which looks pretty involved but might be what I need. Any insights?
Asked by Sterling Butters (117 rep)
Sep 16, 2020, 07:42 PM
Last activity: Sep 17, 2020, 08:35 PM