What Is gksu And Why Would You Use It?

Businessman with computer in office
Paul Bradbury/OJO Images/Getty Images

 

Introduction

The gksu and gksudo commands allow you to elevate your permissions when running graphical applications.

They are essentially equivalent graphical commands to the su command and the sudo command.

Installation

By default gksu isn't necessarily installed by default any more within all Linux distributions.

You can install it within Ubuntu from the command line using the apt-get command as follows:

sudo apt-get install gksu

You can also install gksu using the synaptic package manager. As of writing this tool isn't available in the main Ubuntu Package Manager.

Why Would You Use gksu

Imagine you are using the Nautilus file manager and you wish to edit a file in a folder owned by another user or indeed a folder that can only be accessed as the root user.

When you open a folder which you have limited permissions to access you will find that options such as create file and create folder are greyed out.

You could open a terminal window, switch to another user using the su command and then create or edit files using the nano editor. Alternatively you could use the sudo command to edit files in places where you don't have the correct permissions.

The gksu application lets you run Nautilus as a different user which means you will have access to the files and folders that are currently greyed out.

How To Use gksu

A simple way to run gksu is to open a terminal window and type the following:

gksu

A small window will open with two boxes:

  • run
  • as user

The run box wants to know the name of the program you wish to run and the as user box lets you decide which user to run the program as.

If you run gksu and enter nautilus as the run command and leave the user as root you will now be able to manipulate files and folders previously inaccessible.

You don't have to use the gksu command on its own. You can specify the command you wish to run and the user all in one as follows:

gksu -u root nautilus


Difference Between gksu And gksudo

In Ubuntu gksu and gksudo perform the same task as they are symbolically linked. (they both point to the same executable).

You should however assume that gksu is the graphical equivalent of the su command which means you have switched to the environment of the user. The gksudo command is equivalent to the sudo command which means you are running the application as the person you are impersonating which by default is root.

Be Careful When Running Graphical Applications With Elevated Permissions

Creating and editing files using Nautilus whilst running as a gksudo or gksu can lead to disastrous consequences.

There is an option within the gksu and gksudo application under the advanced settings which is called preserve environment.

This allows you to access the application with the settings of the currently logged in user but run the application as the user you are impersonating which is commonly root.

Why is this a bad thing?

Imagine the application you are running is the Nautilus file manager and you are logged in as John.

Now imagine that you are using gksudo to run Nautilus as root. You are logged in as John, but running Nautilus as root.

If you start to create files and folders under the home folder you will not necessarily know that the files are being created with root as the owner and root as the group.

When you try and access these files using Nautilus running as the normal John user you won't be able to edit the files.

If the files that were edited were configuration files then this can be very bad indeed.

Should You Use gksu

The gksu page on the GNOME wiki suggests that using gksu is no longer a good idea and it is currently being rewritten to use the policykit.

There is however no viable alternative at present.

How To Add A Run As Root Option To Common Applications In Ubuntu

Imagine you want to be able to add a right click menu to an application so that you can run it as root if you so wished.

Open Nautilus by clicking on the filing cabinet icon on the Ubuntu Launcher.

Click on the "Computer" icon on the left side and navigate to the usr folder, then the share folder and finally the applications folder.

Find the filing cabinet icon with the word "Files" underneath. Right click on the icon and choose "copy to". Now navigate to the home, local, share and applications folder. (You will need to unhide the local folder by right clicking in the home folder and choosing "show hidden files").

Finally click "select"

Now navigate to the home folder and then local, share and applications folder.

Press the super key and type "gedit". A text editor icon will appear. Click on the icon.

Drag the nautilius.desktop icon from the Nautilus window into the editor.

Search for the line that says "Action=Window" and change it to the following:

action=Window,Open Root

Add the following lines at the bottom:

[Desktop Action Open As Root]

Name = Open As Root

Exec = gksu nautilus

Save the file.

Log out an log back in and you will be able to right click on the filing cabinet icon and choose "open as root" to run Nautilus as an administrator.

Summary

Whilst gksu is an option I think that if you needing to perform administrative tasks then you are better off using the terminal