And like this in MATE (GNOME Flashback/Fallback, Xfce, LXDE are similar):
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.
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 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.)
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:
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:~$
gksudo gnome-terminal (assuming gksu is installed)
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.
@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.
As previously stated, you ask how to run Terminal as root, but more likely you actually want to run the graphical Terminal application as your normal user, and start a root shell inside it where you are logged on as root. In this way the graphical terminal application is not granted root privileges. The previous answers don’t seem to give clear command lines to use so here’s what I use.
xterm -bg black -fg red -e sudo -i
The ‘-e sudo -i’ tells xterm to switch to root in the session, and the colours are just to make it very obvious that it’s a root shell.
Go to Keyboard settings, add a custom shortcut with Shortcut Super+X and command ‘xterm -bg black -fg white -sb -sl 5000’, and root xterm with Shortcut Super+Z and command ‘xterm -bg black -fg red -sb -sl 5000 -e sudo -i’.
In the past I have tended to prefer xterm over Gnome Terminal because the font is small and simple, but I’m coming round to Terminal now I run high DPI big screens. Colour coding your terminals is a very good idea once you start to run different profiles with dangerous consequences to avoid accidents (e.g. local root, remote client’s machine, remote client root).
Yes this is exactly what I want to do: «run the graphical Terminal application as your normal user, and start a root shell inside it » I want to run one application as if it was preceded with sudo. I’m starting about 10 programs each in their own terminal, and each requires sudo. I’m using commands like this in the main script: gnome-terminal —title=»airmon» — bash -c ‘sudo airodump-ng wlan0mon —gpsd -C 1 -w $NOW-wlan0_airmon.pcap; $SHELL’ This works, but I have to type my password into all 10 terminals before they start.
If I precede the launch script with sudo sudo ./tenterms.sh , it fails with # Failed to parse arguments: Cannot open display: . I don’t understand your syntax of gnome-terminal — sudo -i with the current gnome-terminal «— » terminates options and starts the command.
@tim11g Regarding your need to type in ‘your password’ (I presume you mean the root password) into each shell, do you know about the /etc/sudoers file? For your second comment, it seems you need to learn about the — command line characters, perhaps you need something like gnome-terminal — sudo -i ./tenterms.sh . From the name, temterms.sh is going to launch 10 terminal applications, so if you run that as root then each terminal will run as root, which isn’t what you are trying to achieve.
That question sounds so simple that there must be a simple solution, right?
Of course you can use gksudo or similar tools but there may be environments where you don’t want to depend on GTK. It’s confusing but a terminal is not a shell !
The terminal is that thing what shows you stuff, where the shell is the thing that has those fancy features like environment variables, conditionals and all that scripting stuff. That’s why x-terminal-emulator -e . just expects a program to run. No scripts possible here, it just starts a new process. When a terminal starts it just knows that there’s some kind of screen showing you stuff and the input of your keyboard which pours directly in there. A shell delivers all the logic of a script language like eg. sh, bash, ash, zsh, .
The other important distinction is who is running the terminal and what shell is running inside it. You may run a terminal in the context of an ordinary user which runs a root shell inside of it but this has some disadvantages eg. when you start a new tab a new shell is spawned but it falls back to the privileges of an ordinary user. Your command of a ‘New shell please’ goes to the terminal and not the shell!
A disappointment when you realize that you have to enter all those sudo stuff once again for every tab you open. Now, is there a way to open a terminal and not a shell as root without using packages like gksudo? Expecting a debian context:
bash -c «xhost +si:localuser:root; ssh-askpass | sudo -S -Hb /usr/bin/xfce4-terminal —default-working-directory=/root»
Although it looks simple a lot stuff is happening here:
et voilà! You have a terminal running as root spawned in the context of the current user. Now when you spawn a new tab it’s happening inside the root terminal instead of the user who spawned it.
Attention! There’s is a reason why this stuff is so complicated. Keep in mind in whatever X|VNC|RDP session you are running it. It just keeps a terminal open. That’s the downside! If someone is able to capture your session (however likely it may be), root access is for free! Your decision.
Adblock