1

I would like to execute the command gedit file.txt as a root with sudo e.g.:

sudo gedit file.txt

should ask me for a root password.

Currently, typing sudo gedit file.txt results in:

[sudo] password for currently_logged_in_user:

After typing the password, it results in:

currently_logged_in_user is not in the sudoers file.
This incident will be reported.

So I have to use su root gedit file.txt instead which is inconvenient.

2
  • I do not want to add the user to sudo list, the question is not a duplicate. I want to use sudo to execute the commands as a root.
    – david
    Jun 27, 2014 at 14:25
  • 1
    There is not a simple way to do what you want. You can configure sudo to allow root access to commands, such as gedit, but not specify files. So if you give a user root access to gedit, the user can edit any system file. I think you will want to change ownership on the file in question so the file is owned by root:some_group, add the user to some_group and allow group edits. Thus gedit does NOT run as root, and the user can edit the file with group permissions. If you need finer grain control use acl. If you really wish to confine a use use apparmor.
    – Panther
    Jun 27, 2014 at 15:26

2 Answers 2

5

sudo does not work the way you envision.

You can configure sudo to allow root access to commands, such as gedit, but not specify files. So if you give a user root access to gedit, the user can edit any system file.

Example, for the user joe

joe     ALL = /usr/bin/gedit

would grant root access to gedit , but the user could then access and edit any file.

In addition, by default, the root account of Ubuntu is locked and sudo uses the invoking users password rather then a root password. Sudo is however highly configurable so you do not have to access root, you can specify an alternate user with the -u flag. You may then configure sudo to use the target password, root or otherwise. You would have to set a root password.

See http://www.gratisoft.us/sudo/sudoers.man.html and https://help.ubuntu.com/community/RootSudofor details

I think you will want to change ownership on the file in question so the file is owned by root:some_group, add the user to some_group and allow group edits.

Example - How to avoid using sudo when working in /var/www?

Thus gedit does NOT run as root, and the user can edit the file with group permissions.

If you need finer grain control use acl.

If you really wish to confine a use use apparmor.

0

it seems your user doesn't have administrative rights and therefore can't invoke sudo. However changing to root user does work. The solution would be to make your current account have administrator rights.

You can do this if you log in to your administrator account and then change it via user accounts.

2
  • I do not want to give my current account administrator rights. I only want to use sudo for executing files as the administrator oneself.
    – david
    Jun 27, 2014 at 14:23
  • I recommend to edit this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.) Mar 23, 2017 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .