Report this

What is the reason for this report?

How To Create a Sudo User on Ubuntu [Quickstart]

Published on March 29, 2016
How To Create a Sudo User on Ubuntu [Quickstart]
This tutorial is out of date and no longer maintained.

Please refer to our Ubuntu 18.04 version of this tutorial instead.

The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu, without having to modify your server’s sudoers file. If you want to configure sudo for an existing user, simply skip to step 3.

Steps to Create a New Sudo User

  1. Log in to your server as the root user.

    1. ssh root@server_ip_address
  2. Use the adduser command to add a new user to your system.

    Be sure to replace username with the user that you want to create.

    1. adduser username
    • Set and confirm the new user’s password at the prompt. A strong password is highly recommended!

      Set password prompts:
      Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
    • Follow the prompts to set the new user’s information. It is fine to accept the defaults to leave all of this information blank.

      User information prompts:
      Changing the user information for username Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
  3. Use the usermod command to add the user to the sudo group.

    1. usermod -aG sudo username

    By default, on Ubuntu, members of the sudo group have sudo privileges.

  4. Test sudo access on new user account

    • Use the su command to switch to the new user account.

      1. su - username
    • As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.

      1. sudo command_to_run
    • For example, you can list the contents of the /root directory, which is normally only accessible to the root user.

      1. sudo ls -la /root
    • The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.

      Output:
      [sudo] password for username:

      If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.

Here is a link to a more detailed user management tutorial:

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author

Mitchell Anicas
Mitchell Anicas
Author
See author profile

Software Engineer @ DigitalOcean. Former Señor Technical Writer (I no longer update articles or respond to comments). Expertise in areas including Ubuntu, PostgreSQL, MySQL, and more.

Still looking for an answer?

Was this helpful?


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

usermod: command not found

That is so helpful. Good steps by step guide.

works great. thanks :)

The tutorials from digital ocean are really a good resource to learn. Thank you.

Very good tutorial, but if I do:

su <my_username>
cd

Says: “cd: /home/<my_username> No such file or directory”

So I created a new user but it doesn’t has home directory. I would like to know if I have to create it or do I miss something. Note: I need the new user has its home directory to install and run some services.

Thank you for the tutorial, I can create an new user. But the thing is I cannot use that account to connect via ssh. Would you have any suggestion?

This comment has been deleted

$ sudo ls -la /root
-su: sudo: command not found

😓

Thank for your writting. From here I have linked to my website https://sonidosgratis.net/. It is very useful for me. Thanks very much

Thanks, Mitch! This was helpful (again).

Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.