How to run GUI applications as root

11,791

The issue with using a straight sudo nautilus is that it will sometimes try to use configuration files from your user's home directory. This can cause root (superpriviledged user) to change permissions on files within your home directory. This is not usually harmful long-term; it can cause annoying problems like refusing to login to your desktop, but you can usually restore previous configurations by typing:

sudo chown -R user:user ~/

So what gksudo and sudo -i do is simply to tell the program to run with either copies of .Xauthority and other configuration files or with ones that actually belong to root. I personally prefer sudo -i so I don't have to type in my password every time, but it's totally preference. The two commands are doing the same thing.

Share:
11,791

Related videos on Youtube

Alejandro_Ubuntu
Author by

Alejandro_Ubuntu

Updated on September 18, 2022

Comments

  • Alejandro_Ubuntu
    Alejandro_Ubuntu almost 2 years

    UPDATE


    I would like to know which is the recommend way of running GUI applications as root, mainly because what I'm trying isn't running smoothly. I get some annoying warnings that makes me think whether I'm doing something wrong or not.

    I'm using gksudo and sudo -i, which I understand, are doing the same thing. Please let me know if there is some slight differences between them.

    Regarding the problems I'm experiencing, I would like to start with nautilus (run as root). I can't edit the preferences file maybe because the program couldn't create its own configuration files. A warning says that the folder /root/.config/nautilus must be created. When you start an application for the first time, the program is responsible for creating the configuration files it will potentially need. So, when you are running as root, it should happen the same, shouldn't it?

    Furthermore, in the shell appears some strange warnings while running this application, such as the followings:

    (nautilus:3406): Gtk-WARNING **: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files Nautilus-Share-Message: Called "net usershare info" but it failed: The "shared network" returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error It doesn't exist the file or the folder Please ask your system administrator to enable user sharing.

    Other applications like gedit or firefox complained in this way:

    (gedit:3444): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

    (gedit:3444): GLib-GIO-WARNING **: Failed to parse translated string ''Monospace 12'' for key 'editor-font' in schema 'org.gnome.gedit.preferences.editor': 0:expected value

    (gedit:3444): GLib-GIO-WARNING **: Using untranslated default instead.

    (firefox:2719): Gtk-CRITICAL **: IA__gtk_clipboard_set_with_data: assertion 'targets != NULL

    I want to make a clean install of the system soon, but before that, I would like to understand how it works in case I need this stuff in the future for specific things. Though I know it's safer to use the straight sudo in the command line instead.

    Why this is happening? Thanks in advance

    • bistoco
      bistoco about 8 years
      This is a good reading askubuntu.com/q/270006/367990
    • ansar313
      ansar313 about 8 years
    • Alejandro_Ubuntu
      Alejandro_Ubuntu about 8 years
      @bistoco Thanks, it helped me to learn some useful things, but not answered what I should do instead. Although I strongly recommend that reading.
    • Takkat
      Takkat about 8 years
      As a beginner you may also want to know about the risks of doing so: askubuntu.com/questions/423040/…
    • Alejandro_Ubuntu
      Alejandro_Ubuntu about 8 years
      Pretty interesting in fact, thank for the advise. The key should be to use the console to avoid side effects. @Takkat
    • Takkat
      Takkat about 8 years
      Yeah, or wait a bit with using sudo until you get more familiar with how the system works and what not to do to not break it - one single command in the command line run in the wrong place or with an erroneous option can make your system unusable. You will need sudo sooner or later but then you will hopefully know how to use it.
  • anonymous2
    anonymous2 about 8 years
    Forgot to mention - the reason you're having problems with configuration probably is because it's using root configuration files instead of your user configs. They may not exist, hence the problems.
  • Alejandro_Ubuntu
    Alejandro_Ubuntu about 8 years
    And why this happens? As I understand, when you start an application for the first time, the program is responsible for creating the configuration files it will potentially need. So, when you are running as root, it should happen the same, no? Thanks for your help! @anonymous2
  • anonymous2
    anonymous2 about 8 years
    Good question. Do you get errors just on nautilus or with all applications? It's relatively normal for some applications to generate warnings, but if you're getting errors with all or most applications, it could be revealing to know what they are. Also, if you run top or some other commandline application as sudo, do you get errors?
  • Alejandro_Ubuntu
    Alejandro_Ubuntu about 8 years
    (nautilus:2176): Gtk-WARNING **: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files Nautilus-Share-Message: Called "net usershare info" but it failed: La «red compartida» devolvió el error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error The file or folder doesn't exists Please ask your system administrator to enable user sharing.
  • Alejandro_Ubuntu
    Alejandro_Ubuntu about 8 years
    Other applications such as gedit or firefox complained in this way: (gedit:2416): GLib-GIO-WARNING **: Failed to parse translated string ''Monospace 12'' for key 'editor-font' in schema 'org.gnome.gedit.preferences.editor': 0:expected value (gedit:2416): GLib-GIO-WARNING **: Using untranslated default instead.sudo (firefox:2719): Gtk-CRITICAL **: IA__gtk_clipboard_set_with_data: assertion 'targets != NULL' failed @anonymous2
  • anonymous2
    anonymous2 about 8 years
    Ok, the message from nautilus is just a Gtk warning. That's relatively normal. I haven't researched it, but I've had that problem sudoing nautilus all the time and it causes no problems. I would try creating /root/.config/nautilus. Make sure put it under root ownership.
  • Alejandro_Ubuntu
    Alejandro_Ubuntu about 8 years
    Thanks for your help. I'm going to open a new specific question to learn more about such warnings.