#!/bin/bash
clear
ftpconf=/etc/vsftpd/vsftpd.conf
begin=$?
while (($begin == 0))
do
echo "#####################################################################"
echo "## 请根据需求选择想要进行的管理操作或配置,提示后输入相应的数字即可 ##"
echo "#####################################################################"
echo "## 1. 安装VSFTPD服务; ##"
echo "## 2. 登录和对匿名用户的设置; ##"
echo "## 3. 配置欢迎信息; ##"
echo "## 4. 设置用户登录后所在的目录; ##"
echo "## 5. 控制用户是否允许切换到上级目录; ##"
echo "## 6. 设置访问控制; ##"
echo "## 7. 设置访问速度; ##"
echo "## 8. 定义用户配置文件; ##"
echo "## 9. 与连接相关的设置; ##"
echo "## 10. FTP工作方式与端口设置; ##"
echo "## 11. 设置传输模式; ##"
echo "## 12. 设置上传文档的所属关系和权限; ##"
echo "## 13. 日志文件相关配置; ##"
echo "## 14. 其他设置; ##"
echo "## 15. 启动或重启服务,并验证服务状态; ##"
echo "## 0. 退出。 ##"
echo "#####################################################################"
read -p "您要进行的操作是[0-15]:" Num
case $Num in
1) clear
echo -e "\033[31m 正在安装VSFTPD服务,请稍后...... \033[0m"
sleep 3
yum -y install vsftpd && echo -e "\033[31m 已安装VSFTPD服务.正在配置开机启动...... \033[0m"
sleep 3
systemctl enable vsftpd && echo -e "\033[31m 已将VSFTPD服务设为开机自启,正在启动VSFTPD服务...... \033[0m"
sleep 3
systemctl start vsftpd && systemctl restart vsftpd && echo -e "\033[031m 已启动VSFTPD服务.正在验证服务启动状态...... \033[0m"
sleep 3
netstat -antlp | grep vsftpd && echo -e "\033[31m 已正常启动VSFTPD服务.正在结束,请稍后...... \033[0m"
sleep 3
;;
2) clear
while (( $begin == 0 ))
do
echo "#####################################################################"
echo "## 登录和对匿名用户的设置 ##"
echo "#####################################################################"
echo "## 1. 是否对登录用户开启写权限; ##"
echo "## 1Y:开启 1N:关闭 ##"
echo "## 2. 是否允许本地用户登录FTP服务器; ##"
echo "## 2Y:允许 2N:拒绝 ##"
echo "## 3. 设置是否允许匿名用户登录FTP服务器; ##"
echo "## 3Y:允许 3N:拒绝 ##"
echo "## 4. 定义匿名用户的账户名称; ##"
echo "## 4Y:username (username为自定义的匿名用户账户名称) ##"
echo "## 5. 匿名用户登录时是否询问口令; ##"
echo "## 5Y:询问 5N:不询问 ##"
echo "## 6. 匿名用户是否允许下载可阅读的文档; ##"
echo "## 6Y:允许 6N:拒绝 ##"
echo "## 7. 是否允许匿名用户上传文件: ##"
echo "## 7Y:允许 7N:拒绝 ##"
echo "## 8. 是否允许匿名用户创建目录; ##"
echo "## 8Y:允许 8N:拒绝 ##"
echo "## 9. 是否允许匿名用户拥有多于上传、建立目录、删除、更名的权限; ##"
echo "## 9Y:允许 9N:拒绝 ##"
echo "#####################################################################"
echo "## 0. 返回上级目录. ##"
echo "#####################################################################"
read -p "您要进行的操作是[1Y-9Y,1N-3N,5N-9N,0]:" onenum
if [[ $onenum == 1Y ]]
then
clear
wey=$(sed -n '/^write_enable=.*/p' $ftpconf | wc -l)
if [[ $wey -eq 0 ]]
then
echo "write_enable=YES" >> $ftpconf
else
sed -i 's/^write_enable=.*/write_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 1N ]]
then
clear
if [[ $wen -eq 0 ]]
then
echo "write_enable=NO" >> $ftpconf
else
sed -i 's/^write_enable=.*/write_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 2Y ]]
then
clear
ley=$(sed -n '/^local_enable=.*/p' $ftpconf | wc -l)
if [[ $ley -eq 0 ]]
then
echo "local_enable=YES" >> $ftpconf
else
sed -i 's/^local_enable=.*/local_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 2N ]]
then
clear
if [[ $ley -eq 0 ]]
then
echo "local_enable=NO" >> $ftpconf
else
sed -i 's/^local_enable=.*/local_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 3Y ]]
then
clear
amey=$(sed -n '/^anonymous_enable=.*/p' $ftpconf | wc -l)
if [[ $amey -eq 0 ]]
then
echo "anonymous_enable=YES" >> $ftpconf
else
sed -i 's/^anonymous_enable=.*/anonymous_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 3N ]]
then
clear
if [[ $amey -eq 0 ]]
then
echo "anonymous_enable=NO" >> $ftpconf
else
sed -i 's/^anonymous_enable=.*/anonymous_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 4Y* ]]
then
clear
anonh=$(sed -n '/^ftp_username=.*/p' $ftpconf | wc -l)
anon=$(echo "$onenum" | awk -F: '{print $2}')
if [[ $anonh -eq 0 ]]
then
echo "ftp_username=$anon" >> $ftpconf
else
sed -i 's/^ftp_username=.*/ftp_username='$anon'/g' $ftpconf
fi
elif [[ $onenum == 5Y ]]
then
clear
napy=$(sed -n '/^no_anon_password=.*/p' $ftpconf | wc -l)
if [[ $napy -eq 0 ]]
then
echo "no_anon_password=YES" >> $ftpconf
else
sed -i 's/^no_anon_password=.*/no_anon_password=YES/g' $ftpconf
fi
elif [[ $onenum == 5N ]]
then
clear
if [[ $napy -eq 0 ]]
then
echo "no_anon_password=NO" >> $ftpconf
else
sed -i 's/^no_anon_password=.*/no_anon_password=NO/g' $ftpconf
fi
elif [[ $onenum == 6Y ]]
then
clear
awroy=$(sed -n '/^anon_world_readable_only=.*/p' $ftpconf | wc -l)
if [[ $awroy -eq 0 ]]
then
echo "anon_world_readable_only=YES" >> $ftpconf
else
sed -i 's/^anon_world_readable_only=.*/anon_world_readable_only=YES/g' $ftpconf
fi
elif [[ $onenum == 6N ]]
then
clear
if [[ $awroy -eq 0 ]]
then
echo "anon_world_readable_only=NO" >> $ftpconf
else
sed -i 's/^anon_world_readable_only=.*/anon_world_readable_only=NO/g' $ftpconf
fi
elif [[ $onenum == 7Y ]]
then
clear
auey=$(sed -n '/^anon_upload_enable=.*/p' $ftpconf | wc -l)
if [[ $aney -eq 0 ]]
then
echo "anon_upload_enable=YES" >> $ftpconf
else
sed -i 's/^anon_upload_enable=.*/anon_upload_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 7N ]]
then
clear
if [[ $aney -eq 0 ]]
then
echo "anon_upload_enable=NO" >> $ftpconf
else
sed -i 's/^anon_upload_enable=.*/anon_upload_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 8Y ]]
then
clear
amwey=$(sed -n '/^anon_mkdir_write_enable=.*/p' $ftpconf | wc -l)
if [[ $amwey -eq 0 ]]
then
echo "anon_mkdir_write_enable=YES" >> $ftpconf
else
sed -i 's/^anon_mkdir_write_enable=.*/anon_mkdir_write_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 8N ]]
then
clear
if [[ $amwey -eq 0 ]]
then
echo "anon_mkdir_write_enable=NO" >> $ftpconf
else
sed -i 's/^anon_mkdir_write_enable=.*/anon_mkdir_write_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 9Y ]]
then
clear
aowey=$(sed -n '/^anon_other_write_enable=.*/p' $ftpconf | wc -l)
if [[ $aowey -eq 0 ]]
then
echo "anon_other_write_enable=YES" >> $ftpconf
else
sed -i 's/^anon_other_write_enable=.*/anon_other_write_enable=YES/g' $ftpconf
fi
elif [[ $onenum == 9N ]]
then
clear
if [[ $aowey -eq 0 ]]
then
echo "anon_other_write_enable=NO" >> $ftpconf
else
sed -i 's/^anon_other_write_enable=.*/anon_other_write_enable=NO/g' $ftpconf
fi
elif [[ $onenum == 0 ]]
then
clear
continue 2
else
echo -e "\033[31m 输入错误!请根据提示输入正确的内容. \033[0m"
sleep 3
fi
done
;;
3) clear
while (( $begin == 0 ))
do
echo "#####################################################################"
echo "## 配置欢迎信息 ##"
echo "#####################################################################"
echo "## 1. 设置比较简单的欢迎信息; ##"
echo "## 1Y:信息内容 ##"
echo "## 2. 设置用户登录时,将要显示输出的文件; ##"
echo "## 2Y:文件绝对路径 ##"
echo "## 3. 设置是否显示目录消息; ##"
echo "## 3Y:显示 3N:不显示 ##"
echo "## 4. 设置目录消息文件; ##"
echo "## 4Y:文件绝对路径 ##"
echo "#####################################################################"
echo "## 0. 返回上级目录. ##"
echo "#####################################################################"
read -p "您要进行的操作是[1Y-4Y,3N,0]:" twonum
if [
CentOS7.5平台下的vsftpd运维脚本(个人练习版)
最新推荐文章于 2024-09-10 13:10:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)