Created
August 26, 2014 14:11
-
-
Save anchoo2kewl/b90640822258392fe2e6 to your computer and use it in GitHub Desktop.
This script helps create a new email account in postfix and dovecot. The domain is hardcoded for my needs because its faster but one may pass the domain as a parameter.
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 | |
# chkconfig: 2345 50 70 | |
SUCCESS=0 | |
FAILURE=1 | |
# | |
if [ $# -ne 1 ] | |
then | |
echo "Usage: createUser {username}" | |
exit $FAILURE | |
fi | |
email="[email protected]" | |
echo "Enter password for $email:" | |
# read password twice | |
read -s -p "Password: " password | |
echo | |
read -s -p "Password (again): " password2 | |
# check if passwords match and if not ask again | |
while [ "$password" != "$password2" ]; | |
do | |
echo | |
echo "Please try again!" | |
read -s -p "Password: " password | |
echo | |
read -s -p "Password (again): " password2 | |
done | |
HASH=$(doveadm pw -s SSHA512 -p$password) | |
#Add to postfix | |
echo -e "$email\t $email" >> /etc/postfix/virtual-mailbox-users | |
echo -e "$email\t$email" >>/etc/postfix/virtual | |
postmap /etc/postfix/virtual | |
#DoveCot | |
echo -e "$email:$HASH" >>/etc/dovecot/passwd.db | |
#RESTART | |
service postfix reload | |
service dovecot restart | |
echo -e "Email account successfully created" | |
exit $SUCCESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment