4

How can I make something like that:

There are two users: user with normal privileges, and administrator with admin privileges.

I want to make it like that:

user@localhost:~$ sudo vim 
[sudo] password for administrator: <admin's password here>

And I am on the administrator account now.

Seth
  • 58,122
LiquidPL
  • 218

3 Answers3

6

Simply add the user to the sudo group:

sudo adduser <username> sudo

More detailed explanation: https://help.ubuntu.com/community/RootSudo#Allowing_other_users_to_run_sudo

If you really need to run vim as a user named "administrator" (not root!) you should use

sudo -u adminstrator vim

But even in that case the normal user has to be member of the sudo group.

  • 1
    This will give root permissions to the user not the administrator account permissions. I agree that in most of the cases, this will be the same as administrator account probably is a sudoer, but not always! :) – laurent Dec 12 '12 at 14:03
  • @laurent: Agreed. I'm assuming "administrator with admin privileges" means smth with root permissions. – Andy Friese Dec 12 '12 at 14:09
  • sure this is a valid assumption in my opinion. I just wanted to point out to the OP that his particular situation could be a little different if (for example) he mounts NFS directories with root_squash but usually it won't be the case. – laurent Dec 12 '12 at 16:26
  • Enhanced answer to adopt laurent's comments. – Andy Friese Dec 12 '12 at 16:40
5

sudo vim would mean to execute the vim command as super-user. If you are looking for the command to start a shell, use

sudo -i

or

sudo su

These will have you type the password of your user, and the user needs to be in the sudoers file.

If you don't want the user to be added to that file, you could just use the command

su

which will have you type in the root (administrator) account.

And finally, if there is an account called administrator, you could do

su administrator

to gain access to that.

Nanne
  • 8,625
  • 3
    +1 for the last part: su administrator is exactly what the OP is asking for (from what I understood). – laurent Dec 12 '12 at 14:07
  • 1
    Please note that sudo su is essentially equivalent to sudo -s (not to sudo -i, which is essentially equivalent to sudo su -). – Eliah Kagan Feb 09 '13 at 13:26
1

If you meant that when logged in as user you want to execute a command as administrator then you need to do:

user@localhost:~$ sudo -u administrator vim

However, the user's password will be asked not the one from adminitrator. To do so you need to run as administrator (hmm) the following command to configure sudo:

visudo

Then scroll down in the opened file and look for other Defaults definition. In this section, preferrably at the end of it, add a new line with:

Defaults targetpw

And save the file and exit. Note that this will change the default behaviour for all sudo users, so if your user administrator needs to use sudo to have root privilege, you would better know the root password!

Huygens
  • 4,713