109

I have always recommended pressing ALT+F2 and typing for example gksu nautilus or gksudo nautilus both are equivalent; to run graphical programs with root privileges. However, I have just installed raring on a test system and this no longer works.

gksu and gksudo are not installed as part of a default raring install; though they are in the repositories. In 12.04 at least gksudo was just a symbolic link to gksu

The reasons I have always done this are because while it is often safe to use sudo under some circumstances it can cause problems with graphical applications because gksu has you running the program as root while with sudo you are running as yourself but with elevated privileges.

This can mean you inadvertently change the owner of critical system files. This can cause problems.

This reasoning is explained better here:

Why was command removed from a fresh install and what should we be using instead?

Warren Hill
  • 22,112
  • 28
  • 68
  • 88
  • 1
  • 5
    As a clarification, gksudo and gksu are not identical, even though one is a symbolic link to another (the program detects how it was initiated). There is a subtle difference that, in rare cases, can lead to the loss of selected system files. Therefore, until you start to use pkexec, please always use gksudo instead of gksu. – Paddy Landau Apr 30 '13 at 10:07
  • 1
    @PaddyLandau I like many others here always 'gksuandgksudo` were the same see What is the difference between gksudo and gksu?. Can you add an answer to that question that explains the difference please; or give us a link to a website that explains it so one of us can. – Warren Hill Apr 30 '13 at 10:17
  • 1
    @WarrenHill - I have posted an answer on that thread for you. – Paddy Landau Apr 30 '13 at 13:42
  • 4
    Worth noticing that none of the answers so far explain why gksu is no longer installed by default, which is the actual question. – MestreLion May 21 '13 at 00:12
  • 3
    @MestreLion. The reason gksu stopped being installed by default is that the developers think polkit is a better way to control privileges. So they have been gradually migrating applications to use that instead. gksu was only part of the default install because other applications depended on it. Since nothing in a default install depends on gksu or gksudo its no longer pulled in as a dependency. – Warren Hill Jun 19 '13 at 15:30
  • 1
    As put by Emmanuele Bassi, a GNOME developer: "there are no real, substantiated, technological reasons why anybody should run a GUI application as root. By running GUI applications as an admin user you're literally running millions of lines of code that have not been audited properly to run under elevated privileges; you're also running code that will touch files inside your $HOME and may change their ownership on the file system; connect, via IPC, to even more running code, etc. You're opening up a massive, gaping security hole. https://goo.gl/1qTQGL – l3x Dec 07 '18 at 02:03

2 Answers2

71

After a long discussion on #ubuntu-devel I now understand the thinking.

gksu can be installed on 13.04 with sudo apt-get install gksu and it will work.

If you decided to install gksu and are using the 64-bit version you'll need to run gksu-properties once to set the authentication to sudo. There is no need to do this on 32-bit as it's set to sudo by default.

However gksu is not recommended any more and it may be removed entirely from future issues of Ubuntu. In general the development team would prefer us not to use GUI applications as root but to use sudo and the command line instead.

In the long term pkexec is preferred however it's not very easy to use at the moment.

pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root.

see the man page man pkexec for more information.

In the mean time you can open a terminal CTRL+ALT+T or search for terminal in dash.

Do not close the terminal until you have finished this is important as the GUI program is a child of the terminal and if you close it the GUI program will also close.

Enter sudo -i

You are now logged on as root so can make the changes you want for example

gedit path_to_file 

to edit a configuration file, or

nautilus 

to run the file manager

When you are finished close the GUI application then in the terminal

exit

You can now close the terminal.

Lesmana
  • 18,386
Warren Hill
  • 22,112
  • 28
  • 68
  • 88
  • 60
    Telling users to use the command line instead of running graphical applications as root isn't going to go over well with Windows converts... – Seth Apr 29 '13 at 20:19
  • 4
    @seth what, they've got dos and powershell now, right? Welcome to the retro-futuristic future, now with more cli. – belacqua May 01 '13 at 17:46
  • @belacqua lol. I actually don't know anyone who uses powershell... A little DOS though. – Seth May 01 '13 at 21:20
  • 5
    By the way, you can void the "closing the terminal kills all spawned programs" issue by launching the program with the & suffix so that it runs as a background process and then issuing disown %1 in bash -- or whatever job number the program is. Then you can safely close the terminal. So, it could be something like: sudo my-program &;disown %1;exit; – Chuck R May 18 '13 at 22:45
  • 18
    However gksu is not recommended any more and it may be removed entirely.... Care to elaborate on why? – MestreLion May 21 '13 at 00:14
  • 2
    As I understand it the problem with sudo, gksu and gksudo is that they elevate a privileges of a process to those of root. Policy kit allows finer control so you can give a process just the privileges it needs and no more. However this requires each program that needs extra privileges to have a profile defining what extra privileges it needs and these are not all in place yet. – Warren Hill May 21 '13 at 06:06
  • 1
    @WarrenHill, I guess you're right. Every application requires a profile in place before use. However, the sudo -i option looks promising. Thanks for passing the info :) – kunaguvarun Aug 07 '13 at 15:08
  • 1
    I find it pretty hard. Try installing new languages on your system. You need to elevate yourself when doing that. Withoug gksu you would need to know the command line and common users can't guess these things. I guess I'm one of them... – Nicolas de Fontenay Aug 18 '13 at 14:46
  • @Githlar Do you really have to use disown? I find that as long as I execute something with &, I can do whatever I want with the terminal, including exit, and nothing happens to any GUI window I spawn with it. If I need to kill it, I'll just run ps aux | grep [program-name] and kill -9 [pid], or just use CtrlQ/Q if it's something like gimp/feh. – Braden Best Jun 16 '15 at 19:23
  • 1
    @ndefontenay Take a look at this, it will help you to use bash at an intermediate level, and if you keep experimenting and pushing the limits of what you can do, you'll end up making some insanely complex scripts. One thing to note is $(command) and function(){}, which are immensely useful. For example, echo "Shell Scripts:"; for f in $(ls); do if [[ $(file $f | grep "Bourne") != "" ]]; then echo "-> $f"; fi; done, will scan the directory and report all of the shell scripts. – Braden Best Jun 16 '15 at 20:02
  • 1
    @B1KMusic Hey! Thanks! I have done a lot of shell scripting around my database management job lately and it comes in very handy. I like my scripts modular so I do use function(){} a lot :) For the loop command, I wonder if a find command piped into an echo would work. – Nicolas de Fontenay Jun 17 '15 at 14:59
  • @ndefontenay no problem! I was once afraid of the terminal, too, and didn't know where to begin, so it's always nice to have a launchpad, so to speak. I've been using Linux for personal use since 2012, so I've had plenty of time to do all sorts of experiments. At this point, the terminal is my preferred method of getting things done, thanks to its versatile, programmable nature. Especially so since I can spend a few seconds typing a for loop, and do something that would take several hours using a graphical file manager. Too bad I can't say the same about the Windows command line. – Braden Best Jun 17 '15 at 17:01
  • 3
    More on windows, using it is just... Slow. Everything about it is slow. The way you do things, the poor excuse for a terminal, installing software, booting and shutting down, removing software, typing commands, attempting to shell script, a task that I can get done within 5 seconds on Linux can take me up to 10 minutes on windows. Inefficient is an understatement. The fact that I feel like I have more control in os x, or in my Android phone, really says something about the design choices of windows. – Braden Best Jun 17 '15 at 17:06
  • 2
    @B1KMusic, it used to be that launching a program from the terminal caused it to exit upon exiting the terminal. That's no longer the case and disown is no longer required. – Chuck R Jun 17 '15 at 20:44
  • @B1Music on desktop windows sucks but on servers powershell is pretty handy. I do DB centric stuff and it works well. The command terminal is useless... – Nicolas de Fontenay Jun 18 '15 at 18:35
  • 1
    @mchid I think so. to test try which pkexec with a clean install. I certainly have it, – Warren Hill Sep 19 '15 at 10:42
  • I am actually using gksu to run bash that prompts for password. So it's not just to run GUI programs as root. – Tomáš Zato Sep 30 '15 at 08:32
  • 1
    The question mentions that "[using sudo instead of gksu] can mean you inadvertently change the owner of critical system files". This answer's use of the -i option to sudo does prevent that from happening (although its importance isn't emphasised). Unfortunately, by using sudo, you lose the other advantage of gksu, namely automatic handling of the ownership of .Xauthority. – MvanGeest Jul 24 '16 at 18:38
  • 1
    "In general the development team would prefer us not to use GUI applications as root" XAMPP's manager has to be run as root, there is no other option. It doesn't matter whether the Ubuntu devs think we should run GUI apps as root, I still need to run GUI apps as root. – Aaron Franke Sep 18 '20 at 23:43
9

I just installed 13.04 : GKSU is already installed...

  • i have just checked .....its installed ....... – Qasim May 01 '13 at 23:40
  • 1
    I was going to make a command about this answer but took a second to check if gksu was there. It is. I even installed a fresh 13.04 64 bit and it was also there. – Luis Alvarado May 02 '13 at 01:14
  • 1
    I've just checked again on my system. Still not there see these threads on Ubuntu Forums here and here. Perhaps it has been added to a recent update, or is it possible you have bought it in by installing something else? – Warren Hill May 02 '13 at 05:49