Create a sudo user in Ubuntu
This article describes how to grant superuser (sudo
) access to a new or existing user on the Ubuntu, Debian, or Debian-based Linux distribution.
Create a new user
- Use
adduser
command followed by the new<username>
:
root@server:~# adduser newuser
- 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:~# visudo
Or you can just directly edit the sudoers file, by using an external editor, such as nano and vim.
root@server:~# nano /etc/sudoers
For detailed information, invoke man sudoers
in your terminal.
Adding the user to sudoers
-
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
In nano, press the CTRL+s to save and then CTRL+x to exit from nano.
Verify the permission change
-
Use
su
followed by the<username>
to switch to the new user account:root@server:~# su - newuser newuser@server:~$
-
Use
sudo -i
to verify that the user account can elevate permissions.
At the prompt, enter the new user's password:
newuser@server:~$ sudo -i
[sudo] password for newuser:
- Use
whoami
to verify that you are currently the root user:
root@server:~# whoami
root
Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.
Updated 9 months ago