A more modern method, given the age of this post, is to place a per-user file in /etc/sudoers.d/ or the appropriate similar location for whatever OS is at reference. So long as your sudoers file contains a line like:
#includedir /etc/sudoers.d
Then a script like this can be used to create a per-user sudoers file for any valid username:
#/usr/bin/env bash
SUDOERS_DIR='/etc/sudoers.d/'
if [ $# -eq 1 ]
then
printf '%s ALL=(ALL:ALL) ALL\n' "$1" > "$SUDOERS_DIR$1" && \
chmod 600 "$SUDOERS_DIR$1"
else
printf 'usage: $0 (username)\n'
printf '(username) will be given sudo privileges\n'
exit 1
fi
With this, an unprivileged user:
/home/jim> sudo -i
Password:
jim is not in the sudoers file. This incident will be reported.
can easily be given sudo access on a per-user basis:
/root# ./addsudo.sh
usage: $0 (username)
(username) will be given sudo privileges
/root# ./addsudo.sh jim
/root# ls -l /etc/sudoers.d/
total 1
-rw------- 1 root wheel 22 Oct 4 15:35 jim
/root# cat /etc/sudoers.d/jim
jim ALL=(ALL:ALL) ALL
And voila:
/home/jim> sudo -i
Password:
/root#
When the time comes to revoke the sudo privileges, simply rm the file for that user:
# rm /etc/sudoers.d/jim