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 main.cf

vim /etc/postfix/main.cf

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/main.cf, in the line of mydestination add “server3.example.com”

mydestination=…..,server3.example.com

send an email to test the SMTP,

echo "hello mary" | mail -s "subject" mary@server3.example.com
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,

newaliases

test the result,

echo "hello harry" | mail -s "subject" harry@server3.example.com
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,

#!/bin/bash
if
   [ "$1" == "user" ];
then
   echo "kernel";
elif
   [ "$1" == "kernel" ];
then
   echo "user";
else
   echo "usage:/root/program kernel|user."
fi

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,

#!/bin/bash
case $1 in
    user)
          echo "kernel" ;;
    kernel)
          echo "user"  ;;
    *)   echo 'usage:/root/program kernel|user.'
esac

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,

anon_upload_enable=YES
anon_mkdir_write_enable=YES

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,

lftp 192.168.0.103

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

chroot_local_user=YES

restart the vsftp

service vsftpd restart

test the result,

ftp 192.168.0.103

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,

chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

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

Comment