WHY IS IT NOT ADVISABLE TO USE SUDO TO OPEN APPLICATIONS WITH USER ROOT PRIVILEGES?

The vast majority of readers open their applications with root user permissions by executing a command of the following type in the terminal:

sudo program_name

The program will open without any problem and we can use it, but it is not the ideal way to do it.

If we use sudo to open graphic applications with root user privileges, we may encounter the following problems:

Sudo can use and modify standard user configuration files

When we run a graphical application with sudo we are opening the application as root user, but we also give the possibility that this program is using certain configuration files stored in our own home.

This fact can cause permissions to be changed for certain program files located in our home ( ~ / ), which may cause the following problems:

  1. A program stops opening when working with our user.
  2. Certain functionalities of a program have an anomalous behavior, for example, that the extensions of our browser are not loaded.
  3. We cannot open a certain file with our normal user account.
  4. Etc.

To avoid this and other possible inconveniences, I recommend you follow the following instructions to open graphical applications as root user.

Note: The chances of having problems opening graphical applications with sudo are small, however it is always sensible to minimize the risks.

HOW TO OPEN APPLICATIONS WITH ROOT USER PRIVILEGES

To open graphic applications with root user permissions we must use the gksudo, kdesudo and beesu commands.

Note: We will have to apply one command or another depending on our desktop environment and / or the distribution we use.

By using the mentioned commands we will avoid the problems just mentioned.

Therefore if we apply a command of the type:

gksudo YOUR_PROGRAM_NAME

We will be able to open the program as root user and we can also be sure that we will be using the root user configuration stored in the / root location .

In this way we have complete security that the permissions of any of the configuration files of our home partition ( ~ / ) will not be modified .

Open programs as root user In Gnome, Xfce, Lxde, Mate, Cinnamon and Openbox

In the Gnome, XFCE, LXDE, Mate, Cinnamon and Openbox desktops we have to follow the following steps to be able to open programs with administrator privileges.

To start we install the gksu package by executing the following command in the terminal:

sudo apt-get install gksu

Once the gksu package is installed we can open programs with administrator privileges. For this we just have to open a terminal and run the gksu command followed by the name of the program we want to open.

Therefore if we want to open the nautilus file manager with root user permissions we have to execute the following command in the terminal:

gksudo nautilus

Once executed, the file manager will open without any problem.

gksudo nautilus

Open programs as root user in KDE

If you intend to open graphical applications with root user permissions in KDE you have to make sure you have installed the kdesu package.

For this we execute the following command in the terminal:

sudo apt-get install kdesu
Note: If your distro does not use the apt-get package manager, they must modify the command that we have just executed.

Once the package is installed, we will be able to launch any program with a graphical interface with administrator privileges.

In this way, if we want to open dolphin with administrator privileges, we only have to execute the kdesudo command followed by the name of the program, which in this case is dolphin:

kdesudo dolphin

Right after executing the command, dolphin will open and we will have administrator privileges.

Open programs with graphical environment and administrator permissions in Fedora and in distro derived from Fedora

In Fedora none of the above commands will work for us. In Fedora we have to use beesu .

To install beesu we open a terminal and execute the following command:

sudo dnf install beesu

Once beesu is installed we will be able to open any application with a graphical environment having administrator privileges.

For this we just have to run the beesu command followed by the program that we want to open as root user, which in my case is gedit:

beesu gedit

Running the command will open gedit with administrator permissions.

CREATE A LAUNCHER TO OPEN A CERTAIN PROGRAM AS A ROOT USER

In all the previous sections we have opened graphical applications as root user using the terminal.

If there is a program that we use often and we want to create a launcher to open it directly without having to use the terminal, we can do it in the following way:

As a first step we execute the following command in the terminal:

gksudo thunar /usr/share/applications

Executing the command will open the file manager in which we will be able to see practically all the .desktop files of the programs installed on our computer.

Note: If they can not find the .desktop file they are looking for in the / usr / share / applications location, they can use catfish to search with the term * .desktop . Another location where you also get used to storing .desktop files is ~ / .local / share / applications /

We look for the program that we want to open as root user and we copy it.

CREATE A LAUNCHER TO OPEN A CERTAIN PROGRAM AS A ROOT USER

Once copied we paste it in the same location.

Then we rename the file that we just pasted with the name that we want. In my case I rename it as File Manager Thunar ROOT

Next we open the .desktop file that we just renamed with a text editor.

Edit file desktop linux

Once the text editor opens, we look for the line that begins with the word Exec .

Once found we add gksudo, kdesudo or beesu after the symbol =

Note: We will have to add gksudo, kdesudo or beesu depending on the desktop environment and / or distro we are using.

As in my case I am using the XFCE environment I will go from having the following line:

Exec=thunar %F

to have the following:

Exec=gksudo thunar %F
code to open programs root linux

Once all the steps have been carried out, we only have to save the changes and the process has finished.

At this time if we go to the menu of our distro we will be able to see the launcher that we have just created.

If we click on the launcher, the thunar file manager will be opened with root user privileges.

ADDITIONAL OPTIONS FROM THE GKSUDO, KDESUO AND BEESU COMMANDS

The gksu, kdesu and beesu commands are not only used to open programs and applications with root user permissions.

These commands also serve to execute and use programs on behalf of any user that we have created on our computer.

So therefore if we want to generate a text file on behalf of a user named martin we can execute the following commands:

On Gnome, Xfce, Lxde, Mate, Cinnamon and Openbox:

gksudo -u martin mousepad

In Where:

kdesudo -u martin kate

In Fedora:

beesu -l -P 'gedit' martin

In addition, these commands usually have a graphical interface to try to facilitate their use. If we open a terminal and execute the gksu, kdesu or beesu command, a graphical interface similar to the following will open:

With this interface we will be able to Open programs and use part of the functionalities of gksu, kdesy and beesu in a simpler way.

For more information on these commands you can consult the man pages of your distribution.

CONCLUSIONS

The conclusions that we have to draw from this article are the following:

  1. To open graphic applications with root user permissions we have to do it with gksudo, kdesudo or beesu.
  2. To open programs that run in the terminal with administrator privileges we have to use the command sudo.

If we apply these simple rules we will avoid having problems with the permissions of our files.

In the event that they decide not to follow this simple advice, nothing has to happen. In 99.9% of cases that open graphic applications with sudo, absolutely nothing will happen, but there is always a small possibility that the permissions of our files will be changed.

Source: https://geekland.eu/abrir-aplicaciones-graficas-como-root/