Created
November 25, 2021 10:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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