If you want to run programs without using Terminal, I can deduce that you mean only GUI programs. And each one from all these GUI applications have in general an .desktop file located in /usr/share/applications/
or in your user directory ~/.local/share/applications
. So to start a program as root you must to edit or better duplicate its associated .desktop file.
Let's take for example Gedit, the default GUI editor in Ubuntu. Its .desktop file is /usr/share/applications/gedit.desktop
and has the following content:
[Desktop Entry]
Name=gedit
GenericName=Text Editor
Comment=Edit text files
Exec=gedit %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=accessories-text-editor
Categories=GNOME;GTK;Utility;TextEditor;
X-GNOME-DocPath=gedit/gedit.xml
X-GNOME-FullName=Text Editor
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gedit
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.10.4
X-GNOME-Bugzilla-ExtraInfoScript=/usr/share/gedit/gedit-bugreport
Actions=Window;Document;
Keywords=Text;Editor;Plaintext;Write;
X-Ubuntu-Gettext-Domain=gedit
[Desktop Action Window]
Name=Open a New Window
Exec=gedit --new-window
OnlyShowIn=Unity;
[Desktop Action Document]
Name=Open a New Document
Exec=gedit --new-document
OnlyShowIn=Unity;
Now create a duplicate of this file as follow:
sudo cp /usr/share/applications/gedit.desktop /usr/share/applications/root_gedit.desktop
and make the following changes:
[Desktop Entry]
Name=gedit as root
GenericName=Text Editor as root
Comment=Edit text files
Exec=gksudo gedit %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=accessories-text-editor
Categories=GNOME;GTK;Utility;TextEditor;
X-GNOME-DocPath=gedit/gedit.xml
X-GNOME-FullName=Text Editor
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gedit
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.10.4
X-GNOME-Bugzilla-ExtraInfoScript=/usr/share/gedit/gedit-bugreport
Actions=Window;Document;
Keywords=Text;Editor;Plaintext;Write;
X-Ubuntu-Gettext-Domain=gedit
[Desktop Action Window]
Name=Open a New Window
Exec=gksudo gedit --new-window
OnlyShowIn=Unity;
[Desktop Action Document]
Name=Open a New Document
Exec=gksudo gedit --new-document
OnlyShowIn=Unity;
After this, when you will search for gedit
in the Dash you will see two instances of gedit: one named Text Editor and one Text Editor as root. You should open that one named Text Editor as root if you want to run gedit as root.
Note: gksudo
must to be installed in order to use it. If you don't have installed, you can install it from terminal using:
sudo apt-get install gksudo
Best Answer
The default terminal emulator on Ubuntu is the GNOME Terminal. It's located at
/usr/bin/gnome-terminal
and can be run with thegnome-terminal
command.What You Really Want
What you probably want is a shell running as root, as though it were produced from a root login (for example, with all the environment variables set for root rather than for your user).
Assuming that's what you want, as steeldriver has suggested, just run:
You'll have a root shell in which commands you enter will be run as root (without having to precede them with
sudo
).But if you really want to run the graphical terminal emulator application as root, read on. I present two ways: with
gksu
/gksdo
, and with thesudo
command.With
gksu
/gksudo
Since you have the gksu package installed, you can run
gnome-terminal
as root with either of:(Since
gksu
is set to sudo-mode in Ubuntu by default, these should be equivalent.)Running
gnome-terminal
as root without a controlling non-root terminal:Virtually every desktop environment provides a facility to run a command without having to open a terminal (which would then, if closed, usually cause the command to be terminated).
This is usually achieved with Alt+F2. A textbox labeled Run command (or similar) will appear and you can enter your command.
For example, it looks like this in Unity:
And like this in MATE (GNOME Flashback/Fallback, Xfce, LXDE are similar):
Note that this works with
gksu
andgksudo
because they use a graphical authentication dialog. If you were to press Alt+F2 and runsudo ...
, you would then be unable to interact with the password prompt.With
sudo
If you don't have the gksu package and you won't want to install it, you can use:
The
-H
flag is important because it sets theHOME
environment variable to/root
instead of your own user's home directory. You should not usesudo gnome-terminal
as it can break the gnome-terminal configuration belonging to the non-root user. For more information about this, see:(
sudo -i gnome-terminal
is also okay.)Getting rid of the controlling non-root terminal:
If you (1) open a graphical terminal, (2) run something like
sudo -H gnome-terminal
in it, to create a new graphical root terminal, and (3) quit the original non-root graphical terminal ...then the root graphical terminal quits as well.This is because the root graphical terminal is sent SIGHUP when the terminal that owns it is exited.
To prevent this, you might think you could instead launch the graphical root terminal with:
But this will only work if
sudo
doesn't have to prompt for a password. If it does, you won't see the password prompt.One way to work around this is to use:
sudo -v
exists for just this purpose. As explained inman sudo
, it "update[s] the user's cached credentials, authenticating the user if necessary."Note that this will still not work if run directly from your desktop environment's Alt+F2 "run command" box, because you still need a terminal to enter your password for
sudo -v
.Or you can do it in what might be called the traditional way, by suspending the job after it starts:
sudo -H gnome-terminal
from the original non-root graphical terminal.sudo
. The graphical terminal will start.exit
. The graphical root terminal job will be both unsuspended and disowned by the non-root terminal, automatically.In short:
But suppose you wanted to keep using the original, non-root terminal too. Then you could run
bg N
, whereN
is the graphical root terminal's job number, to resume the job in the background. You can runjobs
to findN
but you probably won't have to--that number was shown as[N]
when you pressed Ctrl+Z. For example: