System Status
Buy Now
  • Email & Apps
  • Office 365
Login
  • MyRackspace Portal
  • Cloud Control Panel
  • Rackspace Webmail Login
  • Cloud Office Control Panel
  • Support Home
  • How-To
  • Developer Documentation
  •  Blogs 
    • Expert Insights Tech Blog
    • Rackspace Blog
    • Solve: Thought Leadership

Support Network

End-to-End Multicloud Solutions.   Solving Together.™   Learn more at Rackspace.com

How–To Home

Cloud Servers

  • Introduction
  • FAQ
  • All Articles

Create a sudo user in Ubuntu

Last updated on:  2021-05-26

Authored by:  John Garcia


This article describes how to grant sudo access to a new or existing user on the Ubuntu® operating system.

Create a new user

  1. Use adduser command followed by the new <username>:

    root@server-01:~# adduser newuser
    Adding user `newuser' ...
    Adding new group `newuser' (1001) ...
    Adding new user `newuser' (1001) with group `newuser' ...
    Creating home directory `/home/newuser' ...
    Copying files from `/etc/skel' ...
    
  2. 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
    
  3. 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, enter y 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.

  1. Use visudo to edit the sudoers file.

    root@server-01:~# visudo
    
  2. 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 of
    # directly 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 specification
    
    # User alias specification
    
    # Cmnd alias specification
    
    # User privilege specification
    root    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
    
  3. Use the Down Arrow key to scroll to the following section:

    # User privilege specification
    root    ALL=(ALL:ALL) ALL
    
  4. 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
    
  5. Press the Ctrl x to exit. Enter y to save, and click ENTER to finish.

Verify the permission change

  1. Use su followed by the <username> to switch to the new user account:

    root@server-01:~# su - newuser
    newuser@server-01:~$ 
    
  2. 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:~#
    
  3. 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.

Share this information:

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER

About Rackspace
  • About
  • Customer Stories
  • Events
  • Programs
Blogs
  • The Rackspace Blog
  • Expert Insights Tech Blog
  • Solve: Thought Leadership
  • News
  • Contact Information
  • Legal
  • Careers
Site Information
  • Style Guide for Technical Content
  • Trademarks
  • Privacy Statement
  • Website Terms
Support Network
  • Support Network Home
  • Rackspace How-To
  • API Documentation
  • Developer Center
  • ©2020 Rackspace US, Inc.