How to run terminal as root in Kali Linux? How to run a GUI program as root

What needs to be done to make the terminal run as root?

Let's consider several options

1. Switch to root user

In recent versions of Kali Linux, the default user has changed: before it was root, and now it is a regular user.

If you want to revert to the previous option, that is, make the root user the main user, then this is possible.

First, set the root password:

sudo passwd root

Now, when you turn on your computer, you can log in as root:

As a result, all opened terminals will have elevated privileges.

2. Open a root session

Start a terminal with as a normal user and run in it:

sudo su -

A root user session will be opened, all commands will be executed with elevated privileges.

Another option to start a session with elevated privileges is to run the following command:

sudo bash

To end the root session press Ctrl+d.

3. Using sudo, including with internal Bash commands

In fact, few commands require superuser rights. And for those that require root privileges, just run them with sudo:

sudo COMMAND

But what if we need to add a line to a file requiring elevated privileges with the following command:

sudo echo "something" >> /etc/file_requiring_elevated_privileges

The command must be executed with elevated privileges, which should give write permissions to the file. But in this case, neither > nor >> can be used, including as root. And an error like this will be displayed:

bash: /etc/file: Access Denied

You can work around this problem by opening a superuser session:

sudo su -

Or with the tee command. Use it with the --append or -a options - this is important, without these options the file will be completely overwritten. Example:

echo 'new line' | sudo tee --append /etc/apt/sources.list

The above command will append a new line to the existing file.

But the peculiarity of the tee command is that it will not only add the file, but also print the added line to the console. If you do not want the data to be returned to the console again, then redirect the output to /dev/null.

Example:

echo 'new line' | sudo tee --append /etc/apt/sources.list > /dev/null

This will work in a similar way, but no 'new line' will be displayed.

Another use case for echo to write or add to a file as administrator:

sudo sh -c "echo 'something' >> /etc/privilegedfile"

The command uses both single and double quotes, which means that if the string you add to the file also contains quotes, then they must be escaped with backslashes.

4. Using sudo without a password

If it is not a problem for you to add sudo before commands, but you do not like entering a password every time, then the following command will allow you to run commands with sudo and will not be prompted for a password:

echo '%sudo ALL=(ALL) NOPASSWD: ALL' | sudo tee --append /etc/sudoers

Use this only if you understand the security risks!

How to run a GUI program as root

Any program, including those with a graphical interface, can be run as root. This is usually required for file managers and text editors, so that it is convenient to navigate through folders and edit files with limited access.

In fact, everything starts in the same way as with the console utilities:

sudo COMMAND

But you need to know the name of the command. You can find out the name of the command using the following algorithm:

  • open the program you want to run as root
  • look at the menu item “About the program”.

For example, a popular text editor with root privileges can be started like this:

sudo gedit /PATH/TO/FILE

On Kali Linux (Xfce), the file manager executable is called thunar. You can run it as root like this:

sudo thunar

You can also specify the folder you want to open:

sudo thunar /etc

In Cinnamon, the file manager is called Nemo, run as root:

sudo nemo

You can also specify the folder to open:

sudo nemo /etc

Recommended for you:

Leave a Reply

Your email address will not be published. Required fields are marked *