I want to create a user having sudo powers in Ubuntu. How can I do that?
- 4,777
- 1,087
6 Answers
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
addgroupcommand, and then add that group to the sudoers file. Useaddgroup <groupname>to create the group, and then edit the sudoers file (sudo visudo) and add the line%<groupname> ALL=(ALL) ALLto the bottom - Edit the sudoers file with
sudo visudo, and add<username> ALL=(ALL) ALLat the bottom for each user you want to add.
- 235,242
- 38,658
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
- 103
- 1,035
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.
- 8,838
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
- 111
You can also enable root by:
passwd root
and then insert the password for the root
- 123
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
- 179