且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动添加VSFTP服务器虚拟用户脚本

更新时间:2022-09-17 08:11:09

脚本可能写的还不太完善,目前能考虑到的有这么三点:

1、用户名和密码不能为空

2、用户名不能重复

3、当输入用户名正确而密码为空的时候,会自动将之前输入的用户也删除也就是说本次输入失败

4、备份每次修改的用户配置文件,并将保存文件打上时间戳


后面待改进的可以添加输入用户名和字符数量限制等功能


#!/bin/bash

time=`date +%Y%m%d%k%M`

bakfile="user_logn.bak$time"

cp /etc/vsftpd/user_login /etc/vsftpd/vsftpd_bak/$bakfile


echo -n "Enter you want add ftp user's name:" 


read  name   


if [ "$name" = "" ]; then


echo "The name can't be null"


  exit 1 

  

else


grep $name /etc/vsftpd/user_login > /dev/null


  if [ $? -eq 0 ]; then


    echo "The user is exist"


  exit 1


 else


    echo $name >> /etc/vsftpd/user_login

    

       if  [ $? -eq 0 ]; then

            echo "Add user successful!~"

           

           echo -n "Enter you want add ftp user's password:"

           

            read password

            

           if [ "$password" = "" ]; then

              echo "The password can't be null"

              sed -i '$d' /etc/vsftpd/user_login

                exit 1

            else

                  echo $password >> /etc/vsftpd/user_login

                   if  [ $? -eq 0 ]; then

                     echo "Add password successful!~"

           db_load -T -t hash -f /etc/vsftpd/user_login  /etc/vsftpd/user_login.db

                  mkdir /home/vsftp/$name

                  chown ftp_vuser:ftp_vuser /home/vsftp/$name

                  echo "you input name is $name" 

                       echo "password is $password" 

                       echo "Please Mind it!"

                    else

                        echo "password is failed,Please check your input"

                          

                    fi

                    

            fi

         

        else


            echo "Add is failed, Please check the user_login file"


        fi

    fi

            

fi




本文转自 yuri_cto 51CTO博客,原文链接:http://blog.51cto.com/laobaiv1/1838489,如需转载请自行联系原作者