Skip to content

Instantly share code, notes, and snippets.

@kevr
Created February 23, 2014 06:54
Show Gist options
  • Save kevr/9168071 to your computer and use it in GitHub Desktop.
Save kevr/9168071 to your computer and use it in GitHub Desktop.
[root@coders ~]# cat /usr/local/bin/mkuser
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $(basename $0) username \"Full Name\" user@email.tld"
exit 0
fi
tmp="$(pw useradd $1 -w random -o -c "${2}" -s /usr/local/bin/bash -d /usr/home/$1 -m)"
www_groups=$(IFS=' ' read -a arr <<< "$(groups www)"; echo "${arr[@]:1}" | sed 's/ /,/g')
pw usermod www -G ${www_groups},${1}
echo "Creating userdir skeleton..."
mkdir /usr/home/$1/public_html
chown $1:$1 /usr/home/$1/public_html
chmod -R 750 /usr/home/$1
echo "Restarting nginx to reflect new user..."
service nginx restart &> /dev/null
echo "Done!"
echo 'Sending user email...'
from="kevr@coders.ccsfcc.net"
recipients="${3}"
/usr/sbin/sendmail "$recipients" <<EOF
Subject:Account created for coders.ccsfcc.net
From:$from
Your username: ${1}
Your email: ${3}
Your temporary password: ${tmp}
SSH Hostname: coders.ccsfcc.net
SSH Port: 22 (Default)
HTTPS Address: https://coders.ccsfcc.net/~${1}
This account has been setup as a convenience tool to use as you
see fit. However, You may absolutely not run any malicious software,
heavy-load server applications, or host any abnormally large files.
ccsfcc.net Admin
Kevin Morris
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment