When we want to run a programs as root we use sudo, gksu, gksudo and etc. Now my question is how do we can run a Terminal as the root user in Terminal?

I tried with using gksudo terminal and gksu terminal but nothing happens. and by running sudo terminal I get error sudo: terminal: command not found.

share|improve this question
3  
It is gnome-terminal. So try sudo gnome-terminal. – g_p Aug 23 '14 at 19:58
1  
Is there really any advantage to running the terminal program itself as root? why not just start an interactive root shell inside the terminal with sudo -i? – steeldriver Aug 23 '14 at 20:05
2  
@Guru sudo shouldn't be used to run graphical programs like this. If gksu/gksudo isn't (or might not be) installed, sudo -H ... (or sudo -i ...) can be used to run a graphical application ... as root. – Eliah Kagan Aug 23 '14 at 20:26
    
yes, you are correct. – g_p Aug 23 '14 at 20:36
up vote 35 down vote accepted

The default terminal emulator on Ubuntu is the GNOME Terminal. It's located at /usr/bin/gnome-terminal and can be run with the gnome-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:

sudo -i

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 the sudo command.

With gksu/gksudo

Since you have the gksu Install gksu package installed, you can run gnome-terminal as root with either of:

gksu gnome-terminal
gksudo gnome-terminal

(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:

Run a command textbox in Unity

And like this in MATE (GNOME Flashback/Fallback, Xfce, LXDE are similar):

Run Command dialog box in MATE

Note that this works with gksu and gksudo because they use a graphical authentication dialog. If you were to press Alt+F2 and run sudo ..., 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:

sudo -H gnome-terminal

The -H flag is important because it sets the HOME environment variable to /root instead of your own user's home directory. You should not use sudo 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:

sudo -H gnome-terminal &

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
sudo -H gnome-terminal

sudo -v exists for just this purpose. As explained in man 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:

  1. Run sudo -H gnome-terminal from the original non-root graphical terminal.
  2. Enter your password as prompted by sudo. The graphical terminal will start.
  3. Still in the non-root terminal, press Ctrl+Z to suspend the root terminal. While the root terminal is suspended, you can't use it; its interface will not respond to your actions.
  4. Quit the controlling non-root terminal with exit. The graphical root terminal job will be both unsuspended and disowned by the non-root terminal, automatically.

In short:

sudo -H gnome-terminal
^Z
exit

But suppose you wanted to keep using the original, non-root terminal too. Then you could run bg N, where N is the graphical root terminal's job number, to resume the job in the background. You can run jobs to find N but you probably won't have to--that number was shown as [N] when you pressed Ctrl+Z. For example:

ek@Ilex:~$ sudo -H gnome-terminal
[sudo] password for ek: 
^Z
[1]+  Stopped                 sudo -H gnome-terminal
ek@Ilex:~$
share|improve this answer
    
I also can run by xterm. how many terminal exist in Ubuntu? – αғsнιη Aug 23 '14 at 20:35
    
@KasiyA a lot. I once stopped counting at 25. Putty, Terminator are used a lot too. – Rinzwind Aug 23 '14 at 20:41

Short answer:

gksudo gnome-terminal
(assuming gksu is installed)

opens a terminal as root:

root@jacob-Satellite-L300:~#

No need to explain that you can use this to open any terminal as root like this; like Vala (gksudo vala-terminal), Xterm (gksudo xterm), Termit (gksudo termit), UXTerm (gksudo uxterm), Konsole (gksudo konsole) and so on.

share|improve this answer
1  
What about this sudo x-terminal-emulator? – αғsнιη Aug 23 '14 at 20:18
    
@KasiyA You should still use gksu x-terminal-emulator, gksudo x-terminal-emulator, kdesudo x-terminal-emulator (if your desktop environment is KDE), sudo -H x-terminal-emulator, or sudo -i x-terminal-emulator instead, to avoid that problem. Similarly, sudo gedit should not be used to run gedit as root. – Eliah Kagan Aug 23 '14 at 20:21

There's another way to do this, tested and working on Ubuntu 16.04 LTS:

First install gnome-panel:

sudo apt install gnome-panel

Then install gksu:

sudo apt install gksu

After installation is complete, run:

gnome-desktop-item-edit ~/Desktop/ --create-new

This creates a desktop shortcut. You should have the option to name it. I called mine 'X-Term' but you can call yours pretty much whatever you want. Type in /usr/bin/gksu* for the 'Command' path.

When you launch your new desktop shortcut you will be prompted for an application to run. Type in: xterm.

You will now be prompted for your password; once you enter it you'll have access to a working root terminal. Remember to use only when absolutely necessary and close down when you're finished with it.

*assuming you installed Ubuntu with default settings and haven't changed any of the file-systems significantly since installation.

share|improve this answer

You can start an interactive shell with:

sudo -s

For more information do:

man sudo

and read the -s --shell section.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.