Creating Sudo User on Linux Cloud Servers

2019-11-22 By Gary 8993 Views linux sudo
15 reviews

Sudo command allows users to execute the programs with the privileges of other users, especially the default root user. As long as the username is present in the sudoers file, sudo command can be used to execute commands with root user privileges. It runs a single command and requires only the current user password to switch to the root user. This largely helps in increasing system security as well as accidental changes were done to the system.


Sudodiagram


The below steps can be followed to create sudo users with Sudo privileges for CentOS, Ubuntu & Debian.


CentOS


  1. Access the server using SSH.

    # ssh root@server_ip_address
    
  2. Create a new user account using the command useradd. You need to replace newuser with the real username that you want to create.

    # useradd newuser
    
  3. Create a strong password for the user.

    # passwd newuser
    

    *You will be prompted to set and confirm the new user password. Make sure that the password for the new account is as strong as possible.

        The output will be the same as below.
    
    # passwd newuser
            Changing password for user newuser.
            New password:
            Retype new password:
            passwd: all authentication tokens updated successfully.
    
  4. Add User to the Wheel Group.

    By default, the wheel group is a special user group that allows all members in the group to run all commands on CentOS systems. So, need to add the new user to this group so it can run commands as superuser.

    # usermod -aG wheel newuser
    
  5. Switch to newly created user.

    # su - newuser
    


Ubuntu & Debian


  1. Access the server using SSH.

    # ssh root@server_ip_address
    
  2. Create a new user account using the command adduser. You need to replace newuser with the real username that you want to create:

    # adduser newuser
    

    *You will be prompted to set and confirm the new user password. Make sure that the password for the new account is as strong as possible.

    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’ …
    New password:
    Retype new password:
    passwd: password updated successfully
    

    Make sure to use a strong password for your account. The next step is to enter basic information about the user’s account such as name, phone number, etc.

    Enter the user information for newuser
    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. Add User to the sudo group.

    # usermod -aG sudo newuser 
    
  4. Switch to newly created user.

    # su - newuser 
    


Fedora


  1. Access the server using SSH.

    # ssh root@server_ip_address
    
  2. Create a new user account using the command useradd. You need to replace newuser with the real username that you want to create:

    # useradd newuser
    
  3. Create a strong password for the user.

    # passwd newuser
    

    Sudo7

    *You will be prompted to set and confirm the new user password. Make sure that the password for the new account is as strong as possible.

  4. Add User to the Wheel Group.

    # sudo usermod -aG wheel newuser
    
  5. Switch to newly created user.

    # su - newuser
    


Examples for testing Sudo user


The following examples show how a user having sudo permission can execute a command which can only be executed by the root user.


  1. Creating a user named user1 and adding the user to sudo. Sudo1

  2. Testing the working of Sudo, normal user accounts do not have the privilege to add or remove directories under the ownership of the root user. Using Sudo user it is possible to add or remove directories under the ownership of the root user. Sudo2

  3. Installing packages using sudo, normal users do not have the privilege to install applications on the server. Using Sudo user it is possible to install applications on the server.
    Sudo3

    Sudo4

  4. Normal user does not have the privilege to start-stop services. Sudo5

  5. Using Sudo user can start stop services.
    Sudo6


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.