Mainly I am looking for a way to pin an application to the Unity launch bar, and run it as root.
Currently, even if I start the application with sudo, and pin it after it starts, it will start as current user next time.
Sad, but there is no context menu option "run as ...".
Update: I switched to gnome3 and now I'm happy, I'm missing only the search.
If you want the app to always run as root
Pin the application to the launcher as normal.
Locate the applications .desktop file which will be in either:
/usr/share/applications/APPNAME.desktop
~/.local/share/applications/APPNAME.desktop
locate .desktop|grep APPAME
Open with gedit:
Then change the line
to
Save
This command will also keep your environment which is very usefull if you need to connect to others servers and use your private key.
To add a quicklist option to 'Run as root'
Follow steps 1, 2 and 3 above
If the launcher currently doesn't have any other quicklist options, just append this to the end of the document
As this is an old question, with an old answer; To complement @edm's amazing explanation.
As of Ubuntu 18.04 and later, gksudo (
gksu
) is deprecated and so, it does not have an install candidate in the official repositories. An alternative is to use pkexec.Edit the file
/usr/share/applications/APPNAME.desktop
and change the lineto
More details on pkexec here.
In the Main Menu under System, Preferences, type
gksudo
in the Command field of Launcher Properties, e.g.:Your Name field might say:
So users know they may see a password popup and why...
I am not sure about Unity Launcher vs Main Menu. Maybe this helps?
Good luck
The following seems to do the same thing, without needing private attributes:
As a quick and simple alternative to the cumbersome demands described in the answers here, I've gotten in the habit of doing the following...
Enter
gksu nautilus
(
sudo -i nautilus
works, too.)The resulting window falls under the sudo umbrella, so you can use it to access and launch files with sudo-root privileges to your heart's content until it closes. This comes in handy for transitory situations where you don't need a more permanent solution. I use it routinely to extract compressed files into protected system folders, for instance.
Im posting this in-respone to the question @Chris asked in comments :
Suppose you want to create a launcher which will open "file manager(nautilus)" as root. Then you can do this:
Open terminal. Type:
Hit enter. When asked, enter your login password and hit enter. This will open gedit (text editor). Now, paste the following there:
Now, just save it and exit. You are done. Now if you search on dash then you will find a new launcher "Nautilus (Root)". Clicking this will ask you password, and upon authentication nautilus will be opened as root.
Note: Be careful when you are running "Nautilus (Root)". In this mode you can delete almost anything from
/
and break the system.This should perhaps be a comment on Daniel's solution. It works for me, even in Ubuntu 15.04. I had to put the command between quotes
Exec=gksu "nautilus --new-window"
because of the extra argument. Also, somehow, I don't know why, I had to edit the launcher directly in order to keep the original menu (together with the new option). If you drag your own launcher, it will get registered, but you will not have the same menu.In Ubuntu 15.04, the launcher for nautilus is
usr/share/applications/org.gnome.Nautilus.desktop
. You have to use the command line to see the real file name.Further research lead me to what I believe is a better option : http://ubuntuhandbook.org/index.php/2014/04/ubuntu-14-04-add-open-as-rootadministrator-to-context-menu/ . Instead of opening Nautilus entirely as Root, this allows you to open selected directories as Root within Nautilus. Anyway, I checked, and these two options are compatible. If you open Nautilus as Root and then use the second option to open a directory as Root, it simply opens it without asking the password.
To create a shortcut that executes a script with root permissions on Ubuntu
20.04
, you can use:Add the following line to
/etc/sudoers
(sudo gedit /etc/sudoers
)YOURUSERNAME ALL = NOPASSWD: /script/path
Create a desktop shortcut:
gedit ~/Desktop/myshortcut.desktop
Add the following content:
#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=false Exec=sudo /script/path myarg Name=Shortcut Name Comment=Shortcut Comment Icon=/usr/share/icons/Humanity/actions/16/media-playback-start.svg
Right click and the shortcut and choose
Allow Launching
:As of Ubuntu 18.04
gksu
is depreciated,pkexec
requires an install and doesn't always work. Here's another way:Per edm's answer, edit the
.desktop
EXEC line, but prepend only with "sudo ", e.g./usr/bin/nvidia-settings
becomessudo /usr/bin/nvidia-settings
. MenuLibre users (and maybe other GUI menu editors): theCommand
line in MenuLibre sends to theEXEC
line in in the.desktop
file, so you don't need to bother digging the.desktop
file out.If you try this out from the menu now, nothing will happen. Sudo is called with no GUI so nothing happens and it fails silently. This is expected.
In terminal:
sudo visudo
then add at bottom (right click paste):ctrl+o to save, enter, ctrl+X to close file. Should work now.
Since I was also stuck on this I finally found a solution that worked for me on Ubuntu 20.x LTS
echo pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY
in a terminal.desktop
file at/usr/share/applications/
Exec=
your final command should look something like thisExec=pkexec env DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority /usr/sbin/kvpm