in Linux, rhce

RHCE6 Preperation (9) – SMTP,MTA, shell script, ftp

1, Configure SMTP mail service according to the following requiremnets:
— Your mail server should accept mail from remote hosts and localhost
— harry must be able to receive mail from remote hosts

— Mail delivered to mary should spool into the default mail spool for mary /var/spool/mail/mary

install the postfix,

yum install -y postfix

start the postfix and make it auto on when booting,

service postfix start
chkconfig postfix on

modify the

vim /etc/postfix/

the original inet_interfaces is localhost, if needs to receive the internal and external mails, needs to switch on inet_interfaces = all, and comments off localhost, as following,

inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

harry is local user, so he can receive the external mail, mary should spool into the default mail spool for mary /var/spool/mail/mary, this one also no need to do anything.

Restart the service,

service postfix restart
chkconfig postfix on

check ports is on now,

netstat -ntulp | grep :25

check the hostname,

postconf myhostname

if the hostname is incorrect, needs to modify the /etc/postfix/, in the line of mydestination add “”


send an email to test the SMTP,

echo "hello mary" | mail -s "subject"
mail -u mary

2, Configure an email alias your MTA such that mail sent to harry is received by the local user mary

modify the /etc/aliase

vim /etc/aliase

add one line as following, and add harry at the end, mail transferred to mary and harry also can receive mail.

harry mary,harry

update the database,


test the result,

echo "hello harry" | mail -s "subject"
mail -u mary
mail -u harry
chkconfig postfix on

3, Create a shell script /root/program:
–when you input “kernel” parameter to the shell script that will return “user”
–when you input “user” parameter to the shell script that will return “kernel”
–while script no parameter or parameter is wrong,standard error “usage:/root/program kernel|user”

vim /root/program

add the source code,

   [ "$1" == "user" ];
   echo "kernel";
   [ "$1" == "kernel" ];
   echo "user";
   echo "usage:/root/program kernel|user."

here needs  to pay attention to one thing,  [ “$1” == “user” ], there are some spaces in the middle, if you missed out the space, the shell program will not work. test the result, ./program user will output kernel, ./program kernel, will output user, if ./program, it will output “usage:/root/program kernel|user.”

another way to achieve this is by using the case program,

case $1 in
          echo "kernel" ;;
          echo "user"  ;;
    *)   echo 'usage:/root/program kernel|user.'

4, ftp service, allow anonymous to upload file, upload folder path as /var/ftp/upload

lock the local user to home directory, limit certain user to home directory

limit certain user to login to ftp service.

install the vsftp,

yum install vsftp

start the service and make it auto on,

service vsftpd restart
chkconfig vsftpd on

modify the vsftpd.conf,

vim /etc/vsftpd/vsftpd.conf

uncomment following two lines, save and restart the vsftpd service,


restart the service

service vsftpd restart

create the uploading folder,

mkdir -p /var/ftp/upload

change the access right,

chown ftp.ftp /var/ftp/upload
chmod 775 /var/ftp/upload

change the selinux bool value,

getsebool -a | grep ftp
setsebool -P allow_ftpd-anon_write on
Setsebool -P allow_ftpd_anon_full_access on

test the result,


ls and !ls to display the folder,

put post.log

lock the user to home directory,

vim /etc/vsftpd/vsftpd.conf

switch on chroot_local_user


restart the vsftp

service vsftpd restart

test the result,


login as student, and try to go to other folder,

cd /var/ftp

it will return error, “550 failed to change directory”

limit certain user to home directory,

vim /etc/vsftpd/vsftpd.conf

uncomment following two lines,


create file chroot_list,

vim /etc/vsftpd/chroot_list

add sutdent and visitor

limit certain user to login ftp service, modify /etc/vsftpd/ftpusers, to add the users needs to be limited.

vim /etc/vsftpd/ftpusers

Write a Comment


four × two =