sh 自动化安装配置FTP服务器

时间:2024-09-28 14:32:56
 #!/bin/bash
# FPATH=/etc/vsftpd/
FILE=/etc/vsftpd/vsftpd.conf
USERB=ftp01 CON() {
sed -i "s#anonymous_enable=YES#anonymous_enable=NO#g" $FILE #修改配置文件
cat >> $FILE << EOF chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/vsftpd.user_list
chroot_local_user=NO
local_root=/
EOF
} USADD() {
useradd -s /sbin/nologin $USERB        #添加ftp用户
echo "username: $USERB" echo "" | passwd --stdin $USERB &> /dev/null
echo "password: 123456 " echo "$USERB" >> /etc/vsftpd/chroot_list
echo "$USERB" >> /etc/vsftpd/vsftpd.user_list
} SETU() {
yum install vsftpd -y             #yum 安装
sleep
if [ ! -d $FPATH ];then
echo "Error installation"
exit
else
CON
USADD
fi
} CHOI() {
read -p "You suro setup ftp?y|n: " CHOICE #用户确认是否安装
case $CHOICE in
y|yes)
echo "setup..." ;;
n|no)
echo "exit!!.."
exit ;;
*)
echo "NO command"
exit ;;
esac
} if rpm -qa | grep 'vsftp' &> /dev/null;then
echo " vsftp Already exist!!"
exit
else
echo " setup ftp!... "
CHOI
SETU
sleep
fi /sbin/iptables -I INPUT -p tcp --dport -j ACCEPT #防火墙配置
/etc/rc.d/init.d/iptables save
service iptables restart
sleep
service vsftpd start