最近需要搭建vsftpd文档服务器,为了节省时间,就编写了如下两个脚本,一个是针对32位系统的,另一个是针对64位的系统的,以后使用的时候方便。
 
脚本一:
 
#!/bin/sh
#write by kevin
#Auto_create_vsftpd_priv_32
#date 2011-05-04

###########make install vsftpd-pam#################
yum -y install db4 db4-utils db4-devel
wget ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.4.tar.gz
tar xfz vsftpd-2.3.4.tar.gz
cd vsftpd-2.3.4
make clean
sed -i 's/undef/define/g' builddefs.h
make
install -m 755 vsftpd /usr/local/sbin/vsftpd-pam
install -m 644 vsftpd.8 /usr/share/man/man8
install -m 644 vsftpd.conf.5 /usr/share/man/man5
install -m 644 vsftpd.conf /etc/vsftpd-pam.conf
###################################################
set -x
if [ "$i" == "" ];then
length=20
else
length=$i
fi
############configure of login###########
cat>>/home/logins.txt<<EOF
ftpuser
admin@2010.com
ftpadmin
admin@2010.com
EOF
#########################################
echo -e "===============================================\n\n"
echo -e "The logins.txt is configured ok n\n"
echo -e "===============================================\n\n"
 
ftp_pwd_file="/data/path/auto_change_pwd.txt"
mkdir -p /data/path
touch $ftp_pwd_file
chmod 600 $ftp_pwd_file
ip_last=`/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F ":" '{print $2}'|cut -d \. -f3-4`
update_time=`date +"%Y-%m-%d %H:%M:%S"`
echo "$ip_last:" >$ftp_pwd_file
echo "Update_time: $update_time" >> $ftp_pwd_file
echo "====================================================" >>$ftp_pwd_file
login_file=/home/logins.txt
sed -i '$d' $login_file
ftp_pwd=`tr -dc _A-Z-a-z#$%^*-0-9 </dev/urandom |head -c${length}`
echo $ftp_pwd >> $login_file
db_load -T -t hash -f /home/logins.txt /etc/vsftpd_login.db
chmod 600 /etc/vsftpd_login.db
for i in `sed -n '3p' $login_file`
do
if [ $? == 0 ];then
echo -e "$i\t\t\t${ftp_pwd}">> $ftp_pwd_file
echo "==================================================" >> $ftp_pwd_file
else
echo -e "change passwd for $i error" >> $ftp_pwd_file
fi
done
cat>> /etc/pam.d/ftp<<EOF
auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
EOF
useradd -d /home/vsftpd -s /sbin/nologin vsftpd
mkdir /etc/vsftpd_user_conf/
for N in `sed -n 'p;n' $login_file`
do
mkdir /home/vsftpd/$N
cat >>/etc/vsftpd_user_conf/$N<<EOF
local_root=/home/vsftpd/$N
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
EOF
chmod -R 700 /home/vsftpd/$N
chown -R vsftpd.vsftpd /home/vsftpd/$N
done
cat >>/etc/vsftpd-pam.conf<<EOF
listen=YES
listen_port=6006
connect_from_port_20=NO
pasv_max_port=6000
pasv_min_port=5000
tcp_wrappers=YES
anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=NO
dirmessage_enable=YES
message_file=/etc/.message
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
guest_enable=YES
guest_username=vsftpd
virtual_use_local_privs=YES
pasv_enable=YES
local_max_rate=2097152
#max_clients=50
max_clients=100
max_per_ip=2
anon_world_readable_only=NO
user_config_dir=/etc/vsftpd_user_conf
#user_acl_list
#userlist_file=/etc/vsftpd.user_list
#userlist_enable=YES
#userlist_deny=NO
xferlog_enable=YES
xferlog_file=/var/log/xferlog
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
use_localtime=YES
EOF
cat >>/etc/.message<<EOF
Welcome to Teasure's FTP Website.You can upload and download things that you like!
EOF
cat >>/etc/vsftpd.chroot_list<<EOF
ftpuser
ftpadmin
EOF
#start vsftpd
/usr/local/sbin/vsftpd-pam /etc/vsftpd-pam.conf &
echo -e "================================================"
echo -e "service vsfptd-pam is start\n\n"
echo -e "================================================"
exit 0
 

 
****************************************************************************
 
 
 
脚本二:
#!/bin/sh
#write by kevin
#Auto_create_vsftpd_priv_64
#date 2011-05-04
###########make install vsftpd-pam#################
yum -y install db4 db4-utils db4-devel
wget ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.4.tar.gz
tar xfz vsftpd-2.3.4.tar.gz
cd vsftpd-2.3.4
make clean
sed -i 's/undef/define/g' builddefs.h
sed -i 's#/lib/#lib64/#g' ./vsf_findlibs.sh
make
install -m 755 vsftpd /usr/local/sbin/vsftpd-pam
install -m 644 vsftpd.8 /usr/share/man/man8
install -m 644 vsftpd.conf.5 /usr/share/man/man5
install -m 644 vsftpd.conf /etc/vsftpd-pam.conf
###################################################
#set -x
if [ "$i" == "" ];then
length=20
else
length=$i
fi
############configure of login###########
cat>/home/.logins.txt<<EOF
ftpuser
admin@2010.com
ftpadmin
admin@2011.com
EOF
#########################################
echo -e "===============================================\n\n"
echo -e "The logins.txt is configured ok \n\n"
echo -e "===============================================\n\n"
 
ftp_pwd_file="/data/path/auto_change_pwd.txt"
mkdir -p /data/path
touch $ftp_pwd_file
chmod 600 $ftp_pwd_file
ip_last=`/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F ":" '{print $2}'|cut -d \. -f3-4`
update_time=`date +"%Y-%m-%d %H:%M:%S"`
echo "$ip_last:" >$ftp_pwd_file
echo "Update_time: $update_time" >> $ftp_pwd_file
echo "====================================================" >>$ftp_pwd_file
login_file=/home/.logins.txt
sed -i '$d' $login_file
ftp_pwd=`tr -dc _A-Z-a-z#$%^*-0-9 </dev/urandom |head -c${length}`
echo $ftp_pwd >> $login_file
db_load -T -t hash -f /home/.logins.txt /etc/vsftpd_login.db
chmod 600 /etc/vsftpd_login.db
for i in `sed -n '3p' $login_file`
do
if [ $? == 0 ];then
echo -e "$i\t\t\t${ftp_pwd}">> $ftp_pwd_file
echo "==================================================" >> $ftp_pwd_file
else
echo -e "change passwd for $i error" >> $ftp_pwd_file
fi
done
cat> /etc/pam.d/ftp<<EOF
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd_login
EOF
useradd -d /home/vsftpd -s /sbin/nologin vsftpd
mkdir /etc/vsftpd_user_conf/
for N in `sed -n 'p;n' $login_file`
do
mkdir /home/vsftpd/$N
cat >/etc/vsftpd_user_conf/$N<<EOF
local_root=/data/.vsftpd/$N
write_enable=NO
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
EOF
chmod -R 700 /data/.vsftpd/$N
chown -R .vsftpd /data/.vsftpd/$N
chgrp -R .vsftpd /data/.vsftpd/$N
done
cat >/etc/vsftpd-pam.conf<<EOF
listen=YES
#listen_port=21
listen_port=6006
#ftp_data_port=8080
connect_from_port_20=NO
pasv_max_port=6000
pasv_min_port=5000
tcp_wrappers=YES
anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=NO
dirmessage_enable=YES
message_file=/etc/.message
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
guest_enable=YES
guest_username=.vsftpd
virtual_use_local_privs=YES
pasv_enable=YES
local_max_rate=2097152
max_clients=100
max_per_ip=3
anon_world_readable_only=NO
user_config_dir=/etc/vsftpd_user_conf
#user_acl_list
#userlist_file=/etc/vsftpd.user_list
#userlist_enable=YES
#userlist_deny=NO
xferlog_enable=YES
xferlog_file=/var/log/xferlog
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
use_localtime=YES
EOF
cat >>/etc/.message<<EOF
Welcome to Teasure's FTP Website.You can upload and download things that you like!
EOF
cat >/etc/vsftpd.chroot_list<<EOF
ftpuser
ftpadmin
EOF
#start vsftpd
/usr/local/sbin/vsftpd-pam /etc/vsftpd-pam.conf &
echo -e "================================================\n\n"
echo -e "service vsfptd-pam is start\n\n"
echo -e "================================================"
exit 0
 
 
****************************************************************************************