Skip to content

Instantly share code, notes, and snippets.

@teocci
Created November 25, 2021 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save teocci/245e4f917ab641e2e2c1e9a380048013 to your computer and use it in GitHub Desktop.
Save teocci/245e4f917ab641e2e2c1e9a380048013 to your computer and use it in GitHub Desktop.
A simple bash shell script to create a linux user and optionally make them a sudoer
#!/bin/bash
ROOT_UID=0 # Only users with $UID 0 have root privileges.
E_NOTROOT=87 # Non-root exit error.
# Run as root only (sudo counts)
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "You need root priveledges to run this script"
exit $E_NOTROOT
fi
echo -n "### Enter new user name: "
read NEW_USER
adduser $NEW_USER
echo -n "### make new user a sudoer? (y/n) "
read YES
case ${YES} in
y* )
adduser $NEW_USER sudo
;;
* )
continue
;;
esac
su $NEW_USER
echo "Done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment