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