Add Users to the Sudoers List

When connecting to your VPS, you should never login as root, in fact, root logins with password authentication should be disabled.

Instead you should mainly use a none-root account and elevate your access rights to root only when needed.

By default, you can not use sudo with a new user account, so before you can use it, you have to add the user account to the sudoers list.

As root (ironically, yes I know) open the sudoers list for editing by running this command.

Note: If the ‘visudo’ command is not found, you may need to install sudo as this might be removed from some installations (or if you have run Minstall):

In this file, find this row:

and add below

where <username> is the username of the user that you would like to have the ability to elevate to root.

Save the file and exit. Test you newly changed settings by login as the new user and run “sudo”

3 comments for “Add Users to the Sudoers List

  1. May 1, 2013 at 12:58

    running php scripts on craontb, i do this:0 8 * * * * /path/to/test.php >> /path/to/log.txtanything that is outputted in test.php would be appended to log.txtso if my script has:echo date( Y-m-d H:i:s’). hello worldn ;the log.txt would have2008-02-14 01:34:32 hello world

  2. acd
    June 10, 2013 at 18:37

    Hi Mikho, have you considered the group-based model? In debian, the sudo group is set to have sudo access, so you can add a user by usermod -a -G sudo username. In RHEL, Centos and friends, you can uncomment the %wheel line in sudoers and then usermod -a -G wheel to accomplish the same. I find it a lot easier to do group management than to do /etc/sudoers management, especially if you have more than one admin user.

    • June 12, 2013 at 15:38

      I have considered it and it sure is one way to accomplish the same thing. Thats what I find interesting with working with computers, there are so many ways of doing things.

      One “problem” with adding to groups is when you grep /etc/groups for who is members of what groups it wont list the users primary group.

      I’m not saying that your way is wrong in any way. Only providing another solution.

      Thank you for reading and commenting!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.