Search Suggest

Bài đăng

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:

Prerequisites:
1) Working Postfix / Sendmail (example.com 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
#!/bin/bash
# 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 ]
then
  echo "No Arguments passed. Please check, need atleast 2 arguments i.e. username and password."
else
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
newaliases
if [ `echo $?` -eq 0 ]
then
echo "Success."
else
echo "Failed. Please check arguments supplied or syntax and re-run the command once again."
fi
fi

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

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

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

Success.

[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 staff@example.com
Login to each account and see if all the users recieved the same email or not.

Đăng nhận xét