Ubuntu – How to get permissions to edit system configuration files


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?

Best Answer

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.

In Ubuntu 17.10, Wayland is default instead of the traditional X server, and running graphical editors as root is difficult. See Why don't gksu/gksudo or launching a graphical application with sudo work with Wayland? for details.

In Ubuntu 18.04, gksudo is not available in the official repositories. Use sudo -H <text editor> instead, or the admin:// protocol:

gedit admin:///etc/dhcp/dhcpd.config
Related Question