Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I can't seem to edit and save config files in the root system (eg: /etc/dhcp/dhcpd.config); it just says "permission denied" or the save option is blocked in the text editor.

I'm pretty sure I'm a root user, but how do I make sure? If I am a root user, how do I fix this?

share|improve this question

8 Answers 8

up vote 21 down vote accepted

Which text editor are you using? If you are a root user and know the password, try (in a terminal) either:

  • sudoedit /etc/dhcp/dhcpd.config if you are using a terminal-based editor such as nano or are ssh'ing into a server.
  • gksudo <text editor here> /etc/dhcp/dhcpd.config if you are using a GUI-based editor such as gedit

In either case, you'll need to first provide your root password when requested.

In Ubuntu 14.04 onwards, gksudo is not installed by default. You will have to install the gksu package (either from the Software Centre or via sudo apt-get install gksu) to get it.

share|improve this answer

If you don't want to use a terminal, you can invoke a GUI program as root thus (this example is for Gedit):

  1. Hit Alt+F2 to bring up the Run dialog.
  2. Type gksudo followed by the executable name of your program (which might be different from the name displayed by the GUI). For example:

    gksudo gedit
    
  3. Hit Enter.
share|improve this answer

I can't think of a case where root would get permission denied.

In 12.04 you can do it like this: alt+f2 and enter gksudo in the box that appears like this:
enter image description here
You get a box like this and enter gedit and click ok:
enter image description here
Click open:
enter image description here
Just browse to the file:
enter image description here
Done

Warning: There is a super-user/root for a reason. It's so that you don't accidentally put something bad or out of structure in something important by mistake. You should be exceedingly careful that whatever you edit as root is the correct file you mean to edit AND that your syntax is perfect. If other tools are available for editing, it's recommended to use those. For instance, use the visudo terminal command instead of manually editing /etc/sudoers.

Some files that could get messed up are easy to recover from. Others are relatively complicated or you have to use recovery console and a lot of command line.

Yes the recovery console command line seems a little scarier than even this. Just be careful.

share|improve this answer
    
You might need to update this for 13.04 and newer. Some things relating to gksu/gksudo have changed (not sure if that applies to your answer or not though). –  Seth Mar 25 at 22:07
    
It's my understanding sudo now magically exports DISPLAY environment variables and gksu/gksudo have gone or are going away. I haven't checked though. –  hbdgaf Mar 25 at 22:29

You can test if your current shell is running as root a few different ways

~/ > whoami
paul
~/ > sudo whoami
root
~/ > id
uid=1000(paul) gid=1000(paul) groups=1000(devs),4(adm),20(dialout),24(cdrom),…
~/ > sudo id
uid=0(root) gid=0(root) group=0(root)

Other answers give good ways to escalate to root privilege, so I won't repeat those. Assuming you are root and you still can't edit the file /etc/dhcp/dhcpd.config - then very probably someone or some program has used the chattr program to make the file immutable.

From the chattr manual page:

A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

You can find out by using lsattr

lsattr /etc/dhcp/dhcpd.config

If indeed it's immutable you can turn that off like this:

chattr -i /etc/dhcp/dhcpd.config
share|improve this answer

If neither sudo or gksudo work, the other option is the same as all other Linux distributions: su.

E.g.:

su
<texteditor> /etc/dhcp/dhcpd.config

Oh and there is one other issue, its .conf, not .config

share|improve this answer

To be safe back it up using cp /etc/dhcp/dhcpd.config /$HOME/dhcpd.config.backup and run gksu gedit /etc/dhcp/dhcpd.config

Replace gedit with the editor of your choice

you will get such a prompt

password prompt

Enter your password here

A new window opens and you can edit your config there

In case something goes wrong you can restore it from your backup in the home folder

It is denied permission because of the general system of how linux handles permission

Anything in the $HOME folder belongs to the user, whereas anything under / belongs to root. Any file created in an user accessible folder belongs to that user

the /etc/dhcp/dhcpd.conf file you are trying to access belongs to root, and most files created in a /etc/ belongs to root by default for security reasons

You can still edit this file by elevating your permissions

To do this you have a number of ways

  • use su which stands for switch user. Without any attributes to it, it functions as a command to switch to the root account

  • using sudo which elevates your permission for only one command. Its often used only for command-line apps such as CLI text editors like vim,nano etc

  • using gksu which elevates your permission for only one command, but unlike sudo its used for a graphical program such as GUI text editors such as gedit . it uses a graphical prompt to facilitate entering of a password

share|improve this answer

I can't seem to edit and save config files in the root system (eg: /etc/dhcp/dhcpd.config); it just says "permission denied" or the save option is blocked in the text editor.

I'm pretty sure I'm a root user, but how do I make sure? If I am a root user, how do I fix this?

@Matthem
You are absolutely right that you are the administrator, but on Ubuntu, the root user is disabled by default. Which means even if you are the only user on your system, as well as administrator, you cannot sign on as the root user at all, for security reasons.

So, what you can do is:

  1. First, open the file to be edited, edit and save the file (say, example.txt) in your home directory and then go command-line using

    CTRL+ALT+F1 or CTRL+ALT+F2

    and then log-in as you would log-in in GUI (by specifying your username and password) and then trace the file using:

    ls  -al
    

    this would show the different files saved in your cCurrent home directory. Then use:

    sudo mv example.txt /etc/dhcp/
    

    This command would ask for the root user's password. Enter the password and you are done.

  2. Then logout from the command-line by using either logout, exit or CTRL+D.

  3. Then pres CTRL+ALT+F7 to go back to the normal GUI, and now you will be able to see that you have successfully edited the file.

  4. Alternatively, since this way of editing file is a bit lengthy, what you can do is you can change the ownership of those root files and directories to your username (BUT, BEWARE, doing this is harmful, since the next time you try to modify a file will not warn you of the changes and restrictions).

    Anyway to change the ownership of files and directories you can use the following command in the command-line:

    sudo chmod -R your-user-name:admin .
    

    The .(DOT) here represents the parent directory.

    After the command has successfully executed, go to the GUI and select any file in /bin or /root and right-click and select Properties. You will see that you are the owner of the files while group owner is admin.

share|improve this answer

Open your terminal, type gksudo nautilus, enter your password. It will open directory system in a new window. So, you can open and edit/copy/paste any file by opening through that newly opened window. So simple.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.