#!/bin/bash
echo -n "现有的虚拟用户:"
vuser=$(cat /etc/vsftpd/vuser.list |sed ‘2~2d‘)
echo $vuser
vvuser(){
while true
do
read -p "请输入新建虚拟用户的名称:" vvuser
if [[ $vvuser == "" ]]
then
echo "用户名不能为空,重新输入"
echo $vvuser>>/etc/vsftpd/vuser.list
elif grep $vvuser /etc/vsftpd/vuser.list
then
echo "虚拟用户已经存在,重新输入"
else
echo $vvuser>>/etc/vsftpd/vuser.list
vpass
trace
menu
service vsftpd restart &>/dev/null
break
fi
done
}
vpass(){
while true
do
read -s -p "请输入虚拟用户$vvuser的密码:" vpass
echo
if ((${#vpass}==0))
then
echo "密码不能为空,重新输入"
elif ((${#vpass}<=3))
then
echo "密码长度要大于3位,重新输入"
else
echo $vpass>>/etc/vsftpd/vuser.list
db_load -T -t hash -f /etc/vsftpd/vuser.list /etc/vsftpd/vuser.db
break
fi
done
}
config1(){
cd /etc/vsftpd/vuser_dir/
touch $vvuser
echo anon_world_readable_only=yes >$vvuser
echo local_root=$trace/$vvuser >>$vvuser
}
config2(){
chmod o+w $trace/$vvuser
cd /etc/vsftpd/vuser_dir/
touch $vvuser
echo anon_world_readable_only=yes >$vvuser
echo local_root=$trace/$vvuser >>$vvuser
echo anon_upload_enable=yes >>$vvuser
}
trace(){
while true
do
read -p "请输入虚拟用户的根目录:" trace
if [[ $trace == "" ]]
then
echo "虚拟用户的根目录不能为空,重新输入"
elif [[ $trace == "/" ]]
then
echo "虚拟用户的根目录不能为/,重新输入"
elif [[ $(echo $trace |awk ‘{print substr($0,1,1)}‘) != "/" ]]
then
echo "虚拟用户的根目录必须是绝对路径,重新输入"
else
mkdir -p $trace/$vvuser
touch $trace/$vvuser/$vvuser
break
fi
done
}
menu(){
echo -e "\t\t\t***选择虚拟用户$vvuser的权限***"
echo -e "\t1.\t设置具备下载权限"
echo -e "\t2.\t设置具备上传下载权限"
read -p "你的选择是:" choice
if (($choice==1))
then
config1
else
config2
fi
}
vvuser
===
#!/bin/bash
echo -n "现有的虚拟用户:"
vuser=$(cat /etc/vsftpd/vuser.list |sed ‘2~2d‘)
echo $vuser
vuser(){
while true
do
read -p "请输入要删除的虚拟用户名:" vvuser
if [[ $vvuser == "" ]]
then
echo "用户名不能为空,重新输入"
continue
elif ! grep $vvuser /etc/vsftpd/vuser.list
then
echo "虚拟用户不存在,重新输入"
else
deluser
delnamefile
fi
done
}
deluser(){
user=($(cat /etc/vsftpd/vuser.list))
for i in $(seq 0 2 $((${#user[@]}-1)))
do
if [[ ${user[$i]} == $vvuser ]]
then
sed -i $(($i+1)),$(($i+2))d /etc/vsftpd/vuser.list
fi
done
}
delnamefile(){
rm -rf $(grep local_root /etc/vsftpd/vuser_dir/$vvuser |awk -F‘=‘ ‘{print $2}‘)
rm -rf /etc/vsftpd/vuser_dir/$vvuser
rm -rf /etc/vsftpd/vuser.db
db_load -T -t hash -f /etc/vsftpd/vuser.list vuser.db
service vsftpd restart &>/dev/null
echo "删除虚拟用户$vvuser成功"
break
}
vuser
本文出自 “爱武装一辈子” 博客,请务必保留此出处http://menglinux.blog.51cto.com/8733806/1439174
原文:http://menglinux.blog.51cto.com/8733806/1439174