Create a sudo user in Ubuntu
This article describes how to grant sudo access to a new or existing user on the Ubuntu® operating system.
Create a new user
-
Use
adduser
command followed by the new<username>
:root@server-01:~# adduser newuser
Adding usernewuser' ... Adding new group
newuser' (1001) ...
Adding new usernewuser' (1001) with group
newuser' ...
Creating home directory/home/newuser' ... Copying files from
/etc/skel' ... -
At the prompt, enter the password for the new user twice to set and verify it.
New password:
Retype new password:
passwd: password updated successfully -
If you want to add contact information for the new user, enter it at the prompt
or press ENTER to proceed with the defaults. When you finish, entery
to
verify that the entered information is correct:Changing the user information for newuser Enter the new value, or press ENTER for the default Full Name []: New Hire Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y
Grant root permissions for a new or existing user.
-
Use
visudo
to edit the sudoers file.root@server-01:~# visudo
-
Text similar to the following example displays:
GNU nano 4.8 /etc/sudoers.tmp
This file MUST be edited with the 'visudo' command as root.Please consider adding local content in /etc/sudoers.d/ instead ofdirectly modifying this file.See the man page for details on how to write a sudoers file.Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:>Host alias specificationUser alias specificationCmnd alias specificationUser privilege specificationroot ALL=(ALL:ALL) ALL
Members of the admin group may gain root privileges%admin ALL=(ALL) ALL
Allow members of group sudo to execute any command%sudo ALL=(ALL:ALL) ALL
See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.d
-
Use the Down Arrow key to scroll to the following section:
User privilege specificationroot ALL=(ALL:ALL) ALL
-
Add the newly created user by inserting
<username> ALL=(ALL:ALL) ALL
at the end of the user privilege section, as shown in the following example:# User privilege specification root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL
-
Press the Ctrl x to exit. Enter
y
to save, and click ENTER to finish.
Verify the permission change
-
Use
su
followed by the<username>
to switch to the new user account:root@server-01:~# su - newuser
newuser@server-01:~$ -
Use
sudo -i
to verify that the user account can elevate permissions.
At the prompt, enter the new user's password:newuser@server-01:~$ sudo -i [sudo] password for newuser: root@server-01:~#
-
Use
whoami
to verify that you are currently the root user:root@server-01:~# whoami
root
Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.
Updated 18 days ago