How can I modify a file that is owned by root?

27,714

Solution 1

Assuming you are the owner of the operating system in question then you can do something relatively simple. Also assuming the current file is owned by root and group of root then in a terminal you can:

sudo chown your_user:root /path/to/file

You may now edit this file using your normal GUI login.

Once you're done, remember to set it back

sudo chown root:root /path/to/file

To find out more about changing ownership of files see:

man chown

Opening a terminal can be as simple as opening the application bar (name?) and typing "terminal". Using sudo you will be asked for your password to grant you elevated privileges for making the change. See:

man sudo

Solution 2

Its simple, By default in ubuntu nautilus is the file manager.

So open the file manager with root privileges and change your file

sudo nautilus

Solution 3

Whenever you need to edit something as root, you can use sudo. Press Ctrl+Alt+T to open a terminal and then write this command and hit enter:

sudo gedit /path/to/file

Obviously, make sure to change /path/to/file with the actual location of your file. This will open a gedit (a simple text editor) window run by root (the administrator) and will allow you to edit your file.

Solution 4

I'm trying to understand which problem (use case) you actually want to solve.
It looks like you do not actually intend to modify your system files, but to change something in your GUI.
If that's right, see below.


Usually, the best way to make personal changes to files that are part of Ubuntu, is to make a copy of it to your personal files, and modify that. If you can read the file owned by root, you can create a copy, which is owned by you.

Some GUI features even do this automatically in some cases.

As a simple example, if you want to make a change to an existing desktop wallpaper image, you could find the file, copy it, and modify your copy.
Now you can use it as wallpaper image.


(Doing it this way has various advantages, like keeping the original, not creating conflicts when updating the package it belongs to, allowing to do the same for multiple users (and probably more).)

Share:
27,714

Related videos on Youtube

user276606
Author by

user276606

Updated on September 18, 2022

Comments

  • user276606
    user276606 over 1 year

    I installed a program that runs in a browser. I would like to change the background picture it puts up on the screen or modify the existing one. The properties for that file tell me that it is owned by root.

    I am running Ubuntu 12.04 really using Linux for the 1st time. I am trying to make the switch from Windows and finding it laborious :-)

    How can I change that picture file using the GUI? How do I do this with root privileges?

    • jobin
      jobin about 10 years
      What is the location of the file you want to modify?
    • Hunsu
      Hunsu about 10 years
      do You have root privileges?
    • Rinzwind
      Rinzwind about 10 years
      "and finding it laborious" that is good; just stick with it and if needed ask questions here (if not asked before ;-) ). Do keep in mind: learning another operating systems takes time. Lots of it.
    • user276606
      user276606 about 10 years
      it is a file within usr/share folder - I do have root privileges (I do know the password) but not sure you can start the GUI with root rights? And thanks for the encouragement - this is the 2nd time I am trying Linux and I know that persistence has its rewards, this time I'm sticking with it but I understand why it's not mainstream yet :-) - Thank you
    • user276606
      user276606 about 10 years
      well, it really is the 1st time I am giving it a good try :-)
  • jobin
    jobin about 10 years
    The OP would like to have a GUI way of doing this.
  • Jos
    Jos about 10 years
    Should be your_user:root instead of your_user.root.
  • Drew Anderson
    Drew Anderson about 10 years
    Thanks Jos, corrected. Jobin, once the file is owned by the current user you can use any GUI tool you wish. Personally I'm not familiar with running GUI tools under sudo (gksudo?), and these would be tool specific so more difficult to describe here. I would recommend this fairly simple process as it limits the possible damage to a system by an unknown tool making changes as root. But this is a personal opinion.
  • user276606
    user276606 about 10 years
    Thank you guys I will try this and get back to you - it may take me a couple of days. Thanks for the help!
  • terdon
    terdon about 10 years
    Please don't do this. Just open the file with sudo, don't fiddle with changing permissions. Depending on the process using it, changing the permissions might stop the process from running correctly.
  • Drew Anderson
    Drew Anderson about 10 years
    @terdon, Sure, if it is a file editable on the command line then yes, I agree. I have made the assumption that the OP wanted to modify a background picture. This would be easier by taking ownership and then opening in GIMP or something similar.
  • terdon
    terdon about 10 years
    Not at all! How is running 3 commands, one to change ownership, one to run gimp and another to change back easier than running sudo gimo? It is almost never a good idea to recommend changing permissions. That's the whole reason why sudo exists.