vsftpd 一键脚本
#!/bin/bash
#安装VSFTPD服务并使用匿名用户登录
#关闭sellinux
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
if [ $? -ne 0 ]
then
echo "执行命令失败"
fi
#关闭防火墙
systemctl stop firewalld
if [ $? -ne 0 ]
then
echo "关闭防火墙失败"
read -p "是否跳过此步?(yes or no)":no ifs
if [ $ifs -eq "no" ]
then
echo "正在退出此脚本"
sleep 1
fi
else
echo "关闭防火墙成功"
fi
#yum安装vsftpd
yum -y install vsftpd
if [ $? -eq 0 ]
then
echo "vsftpd安装完成。"
else
echo "vsftpd安装失败。"
fi
#配置匿名用户
useradd vsftpd -d /home/vsftpd -s /bin/false
mkdir -p /home/vsftpd/ftp1
echo "ftp1" >> /etc/vsftpd/loginusers.conf
echo "123456" >> /etc/vsftpd/loginusers.conf
db_load -T -t hash -f /etc/vsftpd/loginusers.conf /etc/vsftpd/loginusers.db
chmod 777 /etc/vsftpd/loginusers.db
sed -i 's/^.*/#&/' /etc/pam.d/vsftpd
sed -i '2i\auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers' /etc/pam.d/vsftpd
sed -i '3i\account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers' /etc/pam.d/vsftpd
mkdir /etc/vsftpd/userconf
echo "local_root=/home/vsftpd/ftp1/" >> /etc/vsftpd/userconf/ftp1
echo "write_enable=YES" >> /etc/vsftpd/userconf/ftp1
chmod 777 /home/vsftpd/ftp1
chown vsftpd:vsftpd /home/vsftpd/ftp1
#最后修改主配置文件
sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/' /etc/vsftpd/vsftpd.conf
echo "guest_enable=YES" >> /etc/vsftpd/vsftpd.conf
echo "guest_username=vsftpd" >> /etc/vsftpd/vsftpd.conf
echo "user_config_dir=/etc/vsftpd/userconf" >> /etc/vsftpd/vsftpd.conf
echo "allow_writeable_chroot=YES" >> /etc/vsftpd/vsftpd.conf
echo "virtual_use_local_privs=YES" >> /etc/vsftpd/vsftpd.conf
echo "pasv_min_port=30000" >> /etc/vsftpd/vsftpd.conf
echo "pasv_max_port=31000 " >> /etc/vsftpd/vsftpd.conf
systemctl start vsftpd
if [ $? -eq 0 ]
then
echo "vsftpd配置完成。"
echo "vsftpd服务已启动。"
else
echo "vsftpd配置失败。"
fi