How can I start a program as root using the window manager?

7

1

I sometimes want to start a graphical program explicitly as root. For now I'm starting a terminal and sudo the desired applicaton.

But is there a way to start an application as root directly from its starter (Gnome or KDE)? Something like right-click and "Run as Administrator" in Windows?

Daniel Rikowski

Posted 2009-08-23T17:21:30.617

Reputation: 668

Answers

8

Linux has something but not exactly what you want, when you want ti Run GUI program as root you can press:

ALT + F2

then write the program name with prefix gksudo

gksudo firefox

you can add it to the right click of the mouse by writing some script.

Am1rr3zA

Posted 2009-08-23T17:21:30.617

Reputation: 4 715

It is now eliminated. Package 'gksu' has no installation candidate running Kali 2019 – Musa Haidari – 2019-03-07T08:06:09.960

3

In Gnome, you should be able to create or edit a menu item which points to the application you're running. Prefix it with gksudo so it will prompt you for elevated privileges. This will get you around typing in a terminal or a launcher to kick off the application.

If that doesn't work, you can also do this:

  1. Create a new shell script with the following content (I organize my scripts in a 'bin/' directory in $HOME):

    #!/bin/sh
    gksudo (your command here)

  2. Change permissions on the shell script so it's executable

  3. Edit the menu item which points to the app you want to run and point it to your shell script.

bedwyr

Posted 2009-08-23T17:21:30.617

Reputation: 1 185

2

Edit the launcher that opens the program. If you are using GNOME, put gksudo before the command. If you are using KDE, put kdesudo before the command. You could write a little script and add that to your right-click menu, if you really wanted to, but it might be easier to edit the launcher so you don't have to right click it every time.

Jarek

Posted 2009-08-23T17:21:30.617

Reputation: 121

1

I think lately the preferred way to launch apps as another user is pkexec command args (or it seems like that, I'm not sure). With XFCE you can right click on desktop and create a launcher. Just put pkexec command args in command and that's all.

For graphical programs, you need this:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY command args..

Or you need to edit policy. See there answers:

akostadinov

Posted 2009-08-23T17:21:30.617

Reputation: 1 140