How do I create an administrator user on Ubuntu?

81

23

I want to create a user having sudo powers in Ubuntu. How can I do that?

Mohit Jain

Posted 2010-10-07T06:36:12.177

Reputation: 1 047

Answers

89

First, create the user with:

sudo adduser <username>

You can read more about this command in the man pages of your system with man adduser.

You can then add a user to the sudo group with with the command:

sudo adduser <username> sudo

Note that versions of Ubuntu until 11.10 will use admin as group instead of sudo:

Until Ubuntu 11.10, the Unix group for administrators with root privileges through sudo had been admin. Starting with Ubuntu 12.04 LTS, it is now sudo, for compatibility with Debian and sudo itself. However, for backwards compatibility, admin group members are still recognized as administrators


If your system does not, then we need to mess with the sudoers file to grant sudo permissions. You can read about the sudoers file with man sudoers for details on the exact syntax and available options, but for simplicity's sake, you can do either of the following:

  • Create a group with the addgroup command, and then add that group to the sudoers file. Use addgroup <groupname> to create the group, and then edit the sudoers file (sudo visudo) and add the line %<groupname> ALL=(ALL) ALL to the bottom
  • Edit the sudoers file with sudo visudo, and add <username> ALL=(ALL) ALL at the bottom for each user you want to add.

Darth Android

Posted 2010-10-07T06:36:12.177

Reputation: 35 133

I misread, thinking you had already created the user. Use sudo adduser <username> to create the user, and then use sudo adduser <username> admin to grand them sudo powers. Ex: sudo adduser piemesons and sudo adduser piemesons admin – Darth Android – 2010-10-07T06:52:10.360

@Darth Android adduser: The user `username' does not exist. and what about the password of that user? and its not admin group its giving him adminstrator powers – Mohit Jain – 2010-10-07T06:54:24.153

Its not admin group.. Its adminstrators power. User created. Now i want to give him adminstrator powers.? – Mohit Jain – 2010-10-07T06:55:09.197

adduser: The group `admin' does not exist. – Mohit Jain – 2010-10-07T06:55:49.040

1Sorry, my ubuntu installation creates an admin group which has sudo powers. Read up on the sudoers file (man sudoers) and then sudo visudo to edit the file and grant permissions to whichever users or groups you want. You can use this file to control how sudo behaves, including whether it prompts for a password, or how long to keep a sudo session active (15min is default) – Darth Android – 2010-10-07T06:59:22.043

@Darth Android Yaa here is sudo visudo . I have a line "root ALL=(ALL) ALL". i think i just need to add a another line ie: "myNewUser ALL=(ALL) ALL". What say? – Mohit Jain – 2010-10-07T07:03:00.490

You might also try adding to the sudo group if it exists, or if you have to use the route suggested in my previous comment, either create a new group (sudo addgroup <groupname>) and then add the line %<groupname> ALL=(ALL) ALL to the sudoers file, or simply add individual users with <username> ALL=(ALL) ALL into the sudoers file. – Darth Android – 2010-10-07T07:03:29.083

You might want to add that if you're doing this on desktop, current LTS also puts the initial admin user in some other groups as well. adm, cdrom, sudo, dip, plugdev, lpadmin, and sambashare on a clean install with cat /etc/group | grep testing | cut -f 1 -d : – RobotHumans – 2013-08-24T10:32:06.307

26

The "popular" answer is how to "reimplement", not "how to add the user?". Bare minimum you need to do is this:

usermod -a -G sudo USERNAME

On my particular system, I am a member of the following groups:

usermod -a -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare,libvirtd USERNAME

To verify what you have done:

groups USERNAME

Richard June

Posted 2010-10-07T06:36:12.177

Reputation: 787

2I shared your question in the Ubuntu room since it is more correct. The only thing I might add is that libvirtd is not a default group for a clean install. The rest are. – RobotHumans – 2013-08-25T16:33:54.477

3

Choose System -> Administration -> Users and Groups.

Select Add to add your new user. When you have completed the wizard, choose your new user and click on account type and change from Desktop user to Administrator.

Neal

Posted 2010-10-07T06:36:12.177

Reputation: 8 447

On my 12.04 system you will need to log out and in again before it works. But very easy and simple way to do it. – dennis – 2015-04-05T08:50:47.630

I m on server dude. Only command line :-) – Mohit Jain – 2010-10-07T06:56:37.540

0

If you are really want to create superuser (copy of root but with other password and home directory) and not a sudo user, use UID=0 and GID=0 for new user:

useradd -ou 0 -g 0 john

-o allows you to create non-unique UID (root UID=0)

-u $UID sets $UID

-g $GID sets $GID

Drey

Posted 2010-10-07T06:36:12.177

Reputation: 11

0

You can also enable root by:

passwd root

and then insert the password for the root

Vahid Mirjalili

Posted 2010-10-07T06:36:12.177

Reputation: 113

4This is an horrible answer. NO ONE SHOULD EVER BE USING ROOT DIRECTLY. – Léo Lam – 2015-03-11T14:33:34.993

-2

What I do is adding user to group called wheel, user belonging to that group can execute any administrator command using sudo.

You must enable that feature in /etc/sudoers, uncomment line below %wheel ALL=(ALL) ALL

Gadolin

Posted 2010-10-07T06:36:12.177

Reputation: 181

3I know this is an old answer, but for the benefit of people coming here now: By default in Ubuntu, no wheel group exists, and this is not how administrative abilities are conferred. The sudo group is used (or the admin group -- not to be confused with the other group called adm -- in Ubuntu 11.10 and earlier). – None – 2013-04-02T13:48:17.900