Adding a user to the Sudoers list in Ubuntu 14.04

May 17, 2014 42.6k views
I run: visudo and I'm presented with a blank file. I read a Digital Ocean article on this and apparently there is supposed to be something in here that I can replicate for my main user account. While I am not completely new to running a Linux system, I haven't done it in awhile & I certainly have never used a VPS before where I need to configure this. Figured I would ask here first before I totally just bomb my box and have to start over :p
3 Answers
Try to re-install the package sudo. If this don't work try enter these in the file manually
#

# 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:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(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
If you're already running as root, check to see if the sudoers file exists by typing in:

ls /etc/sudoers

That will kick the file listing out if the file exists. If you have the file available, go with:

# vi /etc/sudoers

You should be able to get to 'insert' mode by pressing 'i' and you will see a notice about it being a read-only file (disregard that since you will be root), enter in the new user, hit escape, and force the file to save by entering in ':wq!'

Hope that helps.

As a root perform:

Step 1: adduser demo
Step 2: gpasswd -a demo sudo
Step 3: passwd demo

Reference: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04

by Justin Ellingwood
When you start a new server, there are a few steps that you should take every time to add some basic security and set a solid foundation. In this guide, we'll walk you through the basic steps necessary to hit the ground running with Ubuntu 14.04.
Have another answer? Share your knowledge.

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