Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Last active December 20, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMorel/6135471 to your computer and use it in GitHub Desktop.
Save BenMorel/6135471 to your computer and use it in GitHub Desktop.
Creates a user account with correct permissions to host a website with Apache.
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: $(basename $0) [name]"
exit 1
fi
message() {
printf '%-60s' "$*"
}
success() {
printf "[\033[32mSUCCESS\033[0m]\n"
}
failure() {
printf "[\033[31mFAILURE\033[0m]\n"
}
try() {
result=$($* 2>&1)
if [ $? -ne 0 ]; then
failure
echo $result
exit 1
fi
success
}
message "Creating user $1"
try useradd "$1"
message "Chmoding home dir"
try find "/home/$1" -type d -exec chmod 2770 {} \;
message "Making apache user belong to this user's group"
try usermod -aG "$1" apache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment