How to add a user to sudoers?

You will probably need to add user to sudoers so they could run commands via sudo.

  1. First you may need to create the user under root.
    Let's say we need to add the new sentry user:

    adduser sentry
    

    you'll see the output like that:

     Adding user `sentry' ...
     Adding new group `sentry' (1000) ...
     Adding new user `sentry' (1000) with group `sentry' ...
     Creating home directory `/home/sentry' ...
     Copying files from `/etc/skel' ...
     Enter new UNIX password:
  2. Then add the new user to the sudo group:

    usermod -aG sudo sentry
    

Another way

  1. Open the /etc/sudoers directly:

    visudo
    

    or

    vi /etc/sudoers
    
  2. Add a new line for the specific user to sudoers file:

     # User alias specification
     sentry    ALL=(ALL:ALL) ALL

Related articles