≡ Menu

Ubuntu Linux: Edit and Open Files That Require Administrator Privileges

There are certain files in Ubuntu Linux (or Unix-like systems) that only root user access or edit. How can I edit and/or open files that requires admin (root) access on a Ubuntu Linux?

Configuration files, server settings and other files in /etc/ usually owned by root user and require editing for configuration purpose on a Linux or Unix-like systems. You can raise privileges using any one of the following mechanism:

  1. sudo command : Execute a command as another user using command line method.
  2. gksudo or gksu command : Execute a command as another user using graphical tool.

Requirements

The normal user needs to be a member of the admin group to raise privileges either via the sudo or gksudo/gksu command. By default, the first user account on a Ubuntu Linux is a member of the admin group. You can verify this by typing the following commands:

## find out your user name ##
who am i 
 
## verify that you are part of either sudo or admin group ##
id 
 
## Or use /etc/group file to verify that you are part of either sudo or admin group ##
egrep -i 'sudo|admin' /etc/group

Sample outputs:

Fig.01:  The normal user needs to be a member of the admin or sudo group.

Fig.01: The normal user needs to be a member of the admin or sudo group.


From the above outputs it is clear that the user named ‘nixcraft’ is part of sudo group on a Ubuntu Linux.

Examples

The nixcraft user is part of the admin or sudo group. All members of the admin group may gain root privileges or allow members of group sudo to execute any command using either CLI or graphical method.

Command line method

The syntax is:

sudo command
sudo command arg1 arg2

Open the Terminal app and edit file called /etc/resolv.conf either using with nano or vi text editor:
sudo nano /etc/resolv.conf
OR
sudo vi /etc/resolv.conf
You need to provide normal user’s password when prompted:

Gif 01: sudo command demo

Gif 01: sudo command demo


You can now edit the file and save it as root user. Please note that by default the sudoers policy caches credentials for five minutes i.e. after running sudo the user has five minutes whereby any subsequent sudo invocations do not require the entering of a password. This can be cleared using the following command:

sudo -K

Graphical method

The syntax is as follows to edit the file /etc/resolv.conf using the gksudo command. First, press ALT-F2 and type the following command in the box (open the terminal app and type the following command):

gksudo gedit /etc/resolv.conf

Sample outputs:

Fig. 02: Press ALT+F2 and type gksudo command

Fig. 02: Press ALT+F2 and type gksudo command


You need to provide normal user’s password when prompted:
Fig.03: Type normal user account password i.e. your own password when promoted to perform admin task

Fig.03: Type normal user account password i.e. your own password when promoted to perform admin task


Finally, gedit will open as follows:
Fig. 04: gedit editing files with administrator privileges

Fig. 04: gedit editing files with administrator privileges

See also
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 1 comment… add one }
  • YtvwlD March 8, 2015, 9:58 am

    You can check in which groups you are by running “groups”, too.

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , ,