Thursday, 1 December 2011

VSFTPD Virtual Users creation BASH Script How To

The BASH scripts presented here are for the VSFTPD server that has been setup using the how to article here http://sudhakarbellamkonda.blogspot.com/2011/11/vsftpd-virtual-users-and-shell-users.html

Do these changes before using the scripts assuming that you have root access.

Create the following vuser subfolder in /etc/vsftpd/ if not done already

#cd /etc/vsftpd
#mkdir vuser


Download the scripts bundle and untar then in /etc/vsftpd/vuser folder
Click here to download http://www.mediafire.com/?j9anm89c8v6pt84
Latest versions and info maintained at vsftpd-virtualuser-bash-scripts 

The scripts:
vuserchk - checks the necessary files and folders necessary for these scripts
vuser.conf - the file containing configuration parameters for these scripts
vuseradd - adds a virtual user
vuserdel - delets a virtual user
vuserres - restores a deleted user
vuserpas - changes a virtual user password
vusersho - displays the user password

The scripts are very verbose and will display messages and errors which are self explanatory.


What the scripts not do:
Deleting a user will remove the user from the active list and the ftp home folder is renamed to $USER-deleted and the deleted user details are copied to a user deleted list. A script to archive and move the tarball to an archive folder is on the back burner.

Panic not be Cautious: Use the scripts wisely and carefully. Please backup before any use at production servers. The scripts have been tested and used without any errors or problems.

Six are the scripts: These scripts are very non intrusive and have a simple logic flow. Prerequisites are BASH, GAWK, SED for the scripts to work. I am hoping to introduce more functionality into the scripts and add a local user ftp home sync'er and a deleted folder archiver, once finished will add them here.

Test them, deploy for ease of mind and relax and let the scripts do the work :).

2 comments:

  1. In file vuserchk, you need to check if previosly exists file /etc/vsftpd/vuser/vuser_del before count lines in that file.

    if [ -e $VUSER_DEL ]
    DTOTREC=`wc -l $CONFIG_ROOT/$VUSER_DEL | cut -c 1-2`
    else
    DTOTREC="No file"
    fi
    echo "Total records in $CONFIG_ROOT/$VUSER_DEL is $DTOTREC"

    ReplyDelete
  2. There is a problem in multiple places in the scripts if you happen to have similar account names, for example "customer" and "customer1".

    Workaround:
    grep $VUSER $CONFIG_ROOT/$VUSER_LIST
    should be replaced by
    grep -w $VUSER $CONFIG_ROOT/$VUSER_LIST

    Similarly,
    awk '/'$VUSER'/ {...
    should be replaced by
    awk '/\<'$VUSER'\>/ {...

    These changes will make sure you'll not select "customer1" when trying to modify/work with "customer".

    Thanks for the script by the way!

    ReplyDelete