0

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:

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?

1 Answers1

0

second link worked:

$ cat /usr/share/polkit-1/actions/org.freedesktop.policykit.virtualbox.policy 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
    <action id="org.freedesktop.policykit.pkexec.virtualbox">
    <description>Run VirtualBox as Admin</description>
    <message>Authentication is required to run VirtualBox as administrator</message>
    <icon_name>virtualbox</icon_name>
    <defaults>
        <allow_any>auth_admin</allow_any>
        <allow_inactive>auth_admin</allow_inactive>
        <allow_active>auth_admin</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/virtualbox</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
    </action>
</policyconfig>

and

$ cat /usr/share/applications/virtualbox.desktop 
[Desktop Entry]
Name=VirtualBox
GenericName=PC virtualization solution

Type=Application Exec=pkexec 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=pkexec virtualbox Name=Open Oracle VM Manager (admin)