在vsftp的基础上创建虚拟用户的shell script

#!/bin/bash
#Shell name:vuser_ftp.sh
#
#Program:
# create virtual users for vsftp
#Author:pero
#Email: [email protected]
#History:
# 2012/7/23
#
#
#If you have any opinion please contact me

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH

if [ $UID -ne "0" ]
then
 echo "Runing as root"
 exit 77
fi

#create file of users list

read -p "Please input a virtual name for users:" vname
read -p "Please input a password for users:" vpasswd
read -p "Please input a number to check how many users to be create:" num
read -p "Please input a name for save users info:" name
read -p "Please input a user name in your system fot ftp :" tname

fname=$name.list
cd /etc/vsftpd/
touch $fname

for ((i=1;i<=$num;i++))
do
 echo "$vname$i" >> $fname
 echo "$vpasswd" >> $fname
 touch $vname$i
 ys=$(($i % 2)) 
 if [ $ys -eq 0 ]
 then
  echo "anon_world_readable_only=NO" >> $vname$i
  echo "anon_upload_enable=NO" >> $vname$i
  echo "anon_mkdir_write_enable=NO" >> $vname$i
  echo "anon_other_write_enable=NO" >> $vname$i
  echo "local_root=/down" >> $vname$i
  echo "download_enable=YES" >> $vname$i
 else
  echo "anon_world_readable_only=NO" >> $vname$i
  echo "anon_upload_enable=YES" >> $vname$i
  echo "anon_mkdir_write_enable=YES" >> $vname$i
  echo "anon_other_write_enable=YES" >> $vname$i
  echo "local_root=/up" >> $vname$i
  echo "download_enable=NO" >> $vname$i
 fi
done

#db4

db=$(rpm -qa |grep db4 |wc -l)

if [ $db -eq 0 ]
then
 yum install db4 -y &> /dev/null
fi

db_load -T -t hash -f $fname $name.db
chmod 600 /etc/vsftpd/$name.*

#

echo "auth required /lib/security/pam_userdb.so db=/etc/vsftpd/$name" > /etc/pam.d/$name
echo "account required /lib/security/pam_userdb.so db=/etc/vsftpd/$name" >> /etc/pam.d/$name

#
conf=/etc/vsftpd/vsftpd.conf
vdir=/etc/vsftpd/vconf

echo "#-----------------------$name.config--------------------------"
echo "guest_enable=YES" >> $conf
echo "guest_username=${tname}" >> $conf
echo "pam_service_name=${name}" >> $conf
echo "user_config_dir=/etc/vsftpd/vconf" >> $conf

mkdir -p $vdir

mv  $vname* $vdir

cd $vdir

mkdir /up /down
chmod 777 /up /down
chmod o+t /up /down

 

你可能感兴趣的:(shell,script)