PureFTPD安装备忘
因为只是内部使用,所以没有启用Mysql,用PureDB的方式
Pureftp有一个很好用的功能,编译时加上–with-virtualchroot 可以让用户突破chroot,这个就可以实现在win上类似serv-u或g6之类的虚拟目录的功能了,无需通过mount的方式,写了个简单的脚本实现自动安装
安装完成后puureftp的执行文件和文档放在/usr/local/pureftpd
配置文件放在/etc/pureftpd
自动添加pureftpd服务并设置为开机启动
脚本如下:
#!/bin/bash
ver=1.0.30
sbindir=/usr/local/pureftpd
etcdir=/etc/pureftpd
cd /usr/local/src
wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-$ver.tar.gz
tar zxvf pure-ftpd-$ver.tar.gz
cd pure-ftpd-$ver
./configure --with-altlog --with-puredb --with-extauth --with-cookie --with-throttling --with-ftpwho --with-ratios --with-quotas --with-welcomemsg --with-uploadscript --with-virtualhosts --with-virtualchroot --with-diraliases --with-peruserlimits --with-rfc2640 --with-language=simplified-chinese --prefix=$sbindir --sysconfdir=$etcdir
make
make install
cp configuration-file/pure-config.pl $sbindir/sbin/
chmod 755 $sbindir/sbin/pure-config.pl
mkdir -p $etcdir
cp configuration-file/pure-ftpd.conf $etcdir/
cp contrib/redhat.init /etc/init.d/pureftpd
sed -i 's#/usr/local/sbin/#'$sbindir'/sbin/#g' /etc/init.d/pureftpd
sed -i 's#/usr/local/sbin/pure-ftpwho#'$sbindir'/sbin/pure-ftpwho#g' /etc/init.d/pureftpd
sed -i 's#/etc/pure-ftpd.conf#'$etcdir'/pure-ftpd.conf#g' /etc/init.d/pureftpd
chmod 755 /etc/init.d/pureftpd
chkconfig --add pureftpd
chkconfig pureftpd on
echo PATH=$PATH:/usr/local/pureftpd/bin/ >>/etc/profile
source /etc/profile
sed -i 's$# PureDB /etc/pureftpd.pdb$PureDB /etc/pureftpd/pureftpd.pdb$g' $etcdir/pure-ftpd.conf
为了避免一些软件自动扫描21端口,我们往往会更改FTP默认的21端口为其他大于1024的端口,比如21221
更改pureftpd.conf
Bind 0.0.0.0,21221
PassivePortRange 50000 50100 #可能只需要开一小部分的端口
如果服务器开启了iptables,打开/etc/sysconfig/iptables-config,保证此文件定义加载了ip_conntrack_ftp,如:
IPTABLES_MODULES="ip_conntrack_ftp"
然后在文件/etc/modprobe.conf增加此模块的参数:
options ip_conntrack_ftp ports=2121
重启iptables服务即可
用户管理脚本
自己做了一个用户管理脚本,但是不如下面这个写的全面,作者:deccmtd
#!/bin/bash
#
#
# functions: Pureftpd script
# author: Hu ShuangFeng
# version 1.0: 2010-08-10.
#
FTP=/usr/local/pureftpd/bin/pure-pw
mkpasswd=`mkpasswd -l 22 -d 5 -C 5 > /tmp/pureftpdoo`
passwd1=`sed '1 w /tmp/pureftpdoo1' /tmp/pureftpdoo`
passwd2=`cat /tmp/pureftpdoo >> /tmp/pureftpdoo1`
passwd=/tmp/pureftpdoo1
while echo "==================================="
do
printf "What Are You Doing? /n /n1:UserAdd /n2:UserMod /n3:UserPasswd /n4:UserDel /n5:ListAllUser /n6:ListOneUser /n7:List And Delete User /n8:ShowUser /nq:Exit /n /n===================================/nEnter number: " ; read number
while [ "$number" != "1" ]&&[ "$number" != "2" ]&&[ "$number" != "3" ]&&[ "$number" != "4" ]&&[ "$number" != "5" ]&&[ "$number" != "6" ]&&[ "$number" != "q" ]&&[ "$number" != "7" ]&&[ "$number" != "8" ]&&[ "$number" != "9" ]&&[ "$number" != " " ]
do
printf "Please enter the correct option :" ; read number
done
case "$number" in
1)
printf "Please Enter a user name :" ; read name
printf "/nYou directory is [`pwd`] ? /nPlease confirm /"yes/" or /"no/" :" ; read dddd
while [ "$dddd" != "yes" ]&&[ "$dddd" != "no" ]&&[ "$dddd" != "y" ]&&[ "$dddd" != "n" ]&&[ "$dddd" != " " ]
do
printf "Please enter the correct option /"yes/" or /"no/" :" ; read dddd
done
case "$dddd" in
y)
$FTP useradd $name -u nobody -g nobody -d `pwd` -m < $passwd
echo "-----------------------------------"
echo " "
echo "Users [$name] create successful ! "
echo " "
printf "You user name is : $name /n"
printf "You Password is : $passwd1 /n"
printf "You directory is : `pwd` /n"
echo " "
;;
yes)
$FTP useradd $name -u nobody -g nobody -d `pwd` -m < $passwd
echo "-----------------------------------"
echo " "
echo "Users [$name] create successful ! "
echo " "
printf "You user name is : $name /n"
printf "You Password is : $passwd1 /n"
printf "You directory is : `pwd` /n"
echo " "
;;
n)
printf "Please enter the directory : " ; read directory
while [ `echo "$directory" | grep "^/" |wc -l` != "1" ]
do
printf "Please enter the correct directory:" ; read directory
done
$FTP useradd $name -u nobody -g nobody -d $directory -m < $passwd
echo "-----------------------------------"
echo " "
echo "Users [$name] create successful !"
echo " "
printf "You user name is : $name /n"
printf "You Password is : $passwd1 /n"
printf "You directory is : $directory /n"
echo " "
;;
no)
printf "Please enter the directory : " ; read directory
while [ `echo "$directory" | grep "^/" |wc -l` != "1" ]
do
printf "Please enter the correct directory:" ; read directory
done
$FTP useradd $name -u nobody -g nobody -d $directory -m < $passwd
echo "-----------------------------------"
echo " "
echo "Users [$name] create successful !"
echo " "
printf "You user name is : $name /n"
printf "You Password is : $passwd1 /n"
printf "You directory is : $directory /n"
echo " "
;;
esac
;;
2)
printf "Please enter a user name :" ; read name
printf "Please enter a new directory :" ; read newdirectory
$FTP usermod $name -u nobody -g nobody -d $newdirectory -m
echo "-----------------------------------"
echo " "
echo "User [$name] modify a successful !"
echo " "
printf "You user name is : $name /n"
printf "You new directory is : $newdirectory /n"
echo " "
;;
3)
printf "Please enter a user name :" ; read name
$FTP passwd $name -m < $passwd
echo "-----------------------------------"
echo " "
echo "[$name] Password changed successfully !"
echo " "
printf "You user name is : $name /n"
printf "You nwe password is : $passwd1 /n"
echo " "
;;
4)
printf "Please enter a user name :" ; read name
$FTP userdel $name -m
echo "-----------------------------------"
echo " "
printf "You want to delete [$name]? /n /n/"yes/" or /"no/" : " ; read yesno
while [ "$yesno" != "yes" ]&&[ "$yesno" != "no" ]&&[ "$yesno" != "y" ]&&[ "$yesno" != "n" ]
do
printf "Please enter the correct option /"yes/" or /"no/" :" ; read yesno
done
case "$yesno" in
y)
$FTP userdel $name -m
echo "-----------------------------------"
echo " "
echo "Users [$name] have been deleted !"
echo " "
;;
yes)
$FTP userdel $name -m
echo "-----------------------------------"
echo " "
echo "Users [$name] have been deleted !"
echo " "
;;
esac
;;
5)
$FTP list
;;
6)
printf "Please enter a user name :" ; read name
$FTP list | grep $name
echo " "
;;
7)
printf "Please enter a user name :" ; read name
$FTP list | grep $name
echo "-----------------------------------"
echo " "
printf "You want to delete [$name]? /n /n/"yes/" or /"no/" : " ; read yesno
while [ "$yesno" != "yes" ]&&[ "$yesno" != "no" ]&&[ "$yesno" != "y" ]&&[ "$yesno" != "n" ]
do
printf "Please enter the correct option /"yes/" or /"no/" :" ; read yesno
done
case "$yesno" in
y)
$FTP userdel $name -m
echo "-----------------------------------"
echo " "
echo "Users [$name] have been deleted !"
echo " "
;;
yes)
$FTP userdel $name -m
echo "-----------------------------------"
echo " "
echo "Users [$name] have been deleted !"
echo " "
;;
esac
;;
8)
printf "Please enter a user name :" ; read name
$FTP show $name
echo " "
;;
q)
exit
;;
esac
done