#!/bin/bash
#Date:2013.7.11
#system: centos 6.3
if [[ $EUID -ne 0 ]];
then
echo "This script must be run as root" 1>&2
exit 1
fi
read -p "enter your ftp username: " Fname
UserExist=`grep -w $Fname /etc/passwd | wc -l`
while [[ $UserExist -ne 0 ]] ;
do
read -p " your ftp username is your system user,do you want to use it : y/n " Ifconti
if [ $Ifconti == 'y' ] ; then
UserExist=0
else
read -p "please enter another username: " Fname
UserExist=`grep -w $Fname /etc/passwd | wc -l`
fi
done;
read -p "enter your ftp password: " Fpwd
echo $Fpwd
useradd $Fname
echo $Fpwd | passwd --stdin $Fname
Vsftpd=`rpm -qa | grep "vsftpd" | wc -l`
if [ $Vsftpd -ne 0 ] ; then
killall vsftpd
rm -rf /etc/vsftpd
yum -y reinstall vsftpd
else
yum -y install vsftpd
fi
sed -i '12s/YES/NO/' /etc/vsftpd/vsftpd.conf
sed -i '97s/#//' /etc/vsftpd/vsftpd.conf
sed -i '99s/#//' /etc/vsftpd/vsftpd.conf
echo "chroot_local_user=YES" >> /etc/vsftpd/vsftpd.conf
touch /etc/vsftpd/chroot_list
echo $Fname >> /etc/vsftpd/chroot_list
sed -i "/$Fname/d" /etc/vsftpd/user_list
sed -i "/$Fname/d" /etc/vsftpd/ftpusers
service vsftpd start
chkconfig vsftpd on
注:如果你的selinux 开启的话,可能会报vsftpd: 500 OOPS 的错误