Creating a Distribution List in CentOS 5 / 6

Here I am going to explain how to create an alias entry in CentOS 5 / 6 to include all the users on the system. Whenever a mail is sent to an email address all the users must recieve the mail. Here are the steps:

1) Working Postfix / Sendmail ( domain I have taken)
2) Root account is needed to configure the below

Lets create a simple bash shell script to automate our task:

[root@server ~] # vim adduser
# Program to automatically add a new user and set a password for it.
# Syntax to execute the command is adduser <USERNAME> <PASSWORD> 
# Syntax: adduser ahmed p@ssw0Rd
# Author : Ahmed (Nagoor) Shaik
# Created Date : 19th September 2013 12:15 PM IST
echo -e " "
if [ `echo $#` -eq 0 ]
  echo "No Arguments passed. Please check, need atleast 2 arguments i.e. username and password."
echo -e " "
echo "Creating User $1"
useradd $1
echo -e " "
echo "Succesfully created user $1"
echo -e " "
echo $2 | passwd --stdin $1
echo -e " "
find /home/* -maxdepth 0 | cut -d/ -f3 > /etc/postfix/allusers
if [ `echo $?` -eq 0 ]
echo "Success."
echo "Failed. Please check arguments supplied or syntax and re-run the command once again."

[root@server ~] # chmod a+x addusers

Create a user using the script as below
[root@server ~] #  ./adduser ahmed p@ssw0rd

Creating User ahmed
Succesfully created user ahmed
Changing password for user ahmed.
passwd: all authentication tokens updated successfully.


[root@server ~] # vim /etc/aliases
Create an entry as below at the end of file
staff:           :include:/etc/postfix/allusers

Now test by sending a mail to
Login to each account and see if all the users recieved the same email or not.

Post a Comment

Mới hơn Cũ hơn