VSFTPD删除虚拟用户脚本(可批量)

2021-07-12 10:31:56 浏览数 (1)

这篇文章主要功能为自动删除VSFTPD虚拟用户脚本,有需要的朋友可以参考下。(请结合VSFTPD创建虚拟用户脚本(可批量)此文章脚本使用)

脚本内容如下:

#!/bin/bash

#Date:2017-5-20 14:08:55

#Author Blog:

# https://www.yangxingzhen.com

#Author WeChat:

# 微信公众号:小柒博客

#Author mirrors site:

# https://mirrors.yangxingzhen.com

#About the Autho

# BY:YangXingZhen

# Mail:xingzhen.yang@yangxingzhen.com

#Batch deletion of vsftpd virtual users(支持删除单个用户跟多个用户)

#This script applies to Centos 6.x and Centos 7.x

FTP_DIR="/etc/vsftpd"

USER="$*"

if [ $# -eq 0 ];then

echo -e "33[33m Please enter the username that needs to be deleted 33[0m"

echo -e "33[33m Usage: sh $0 {admin|admin123|help} 33[0m"

exit 0

elif [[ ${USER} == "help" ]];then

echo -e "33[33m Please enter the username that needs to be deleted 33[0m"

echo -e "33[33m Usage: sh $0 {admin|admin123|help} 33[0m"

exit 0

fi

for i in `echo ${USER}`

do

grep -qwc "$i" ${FTP_DIR}/ftpusers.txt

if [ $? -eq 0 ];then

sed -i "/^${i}$/, 1"d ${FTP_DIR}/ftpusers.txt

sed -i "/^${i}$/"d ${FTP_DIR}/vsftpd.chroot_list

rm -rf /home/ftpuser/$i

rm -rf ${FTP_DIR}/vsftpd_user_conf/$i

rm -rf ${FTP_DIR}/vsftpd_login.db

db_load -T -t hash -f ${FTP_DIR}/ftpusers.txt ${FTP_DIR}/vsftpd_login.db

chmod 700 ${FTP_DIR}/vsftpd_login.db

echo "`date %Y/%m/%d-%T` $i Delete success" >> ${FTP_DIR}/delete_list.txt

echo -e "33[32m User $i deleting success,Please check the record file >> ${FTP_DIR}/delete_list.txt 33[0m"

else

echo -e "33[32m User $i deleting Fail,This user does not exist 33[0m"

fi

done

0 人点赞