Hi there,
I know this is an old post, but I too was looking to ease the steps in adding vsftp users.
I managed to put together a script using dialogs on centos(based on stuff i found online), to create a simple wizard. Before I lose it, here it is...
This makes it simple for anyone to add a user from the commandline.
here is how you can do it:
1. open a terminal window (command prompt)
2. Create a script called vsftp_add.sh:
"sudo vi /usr/bin/vsftp_add.sh" (or graphically `sudo gedit /usr/bin/vsftp_add.sh`)
3. enter in the following code, and save the file:
Code:
Code:
### VSFTP user add script
#!/bin/bash
# m masseo Jan 7, 2010
#
# This script uses dialog, as a wizardlike interface to add users to an existing vsftp setup.
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root, or use sudo" 1>&2
exit 1
fi
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
USERSFILE="/etc/vsftpd/vsftpd_users.txt"
#FUNCTIONS
function check_name() {
grep $USERNAME $USERSFILE
if [ "$?" = "0" ];
then
NAMEOK="no"
#username exits
dialog --title "ERROR" --msgbox "You have chosen a username that exists already, please try again" 10 50
else
NAMEOK="yes"
fi
}
# Display message with option to cancel
dialog --title "VSFTP user setup" --msgbox "We will now add a new user to this FTP server\" Press <Enter> to start or <Esc> to cancel." 10 50
# Return status of non-zero indicates cancel
if [ "$?" != "0" ]
then
dialog --title "VSFTP" --msgbox "You canceled your user add. Now exiting..." 10 50
else
dialog --title "VSFTP" --infobox "user add in \ process..." 10 50
cd /etc/vsftp
### Prompt user to enter a name
NAMEOK="no"
while [ $NAMEOK != "yes" ];
do
dialog --title "Name" --inputbox "Enter the user you wish to add:" 8 40 2>$tempfile
retval=$?
case $retval in
0)
USERNAME=`cat $tempfile`
check_name
;;
1)
echo "Cancel pressed."
exit 0 ;;
255)
if test -s $tempfile ; then
cat $tempfile
else
exit 0
echo "ESC pressed."
fi
;;
esac
VSFTPUSER=$USERNAME
done
###Prompt to enter password
dialog --title "Name" --inputbox "Please enter a password for $VSFPTUSER:" 8 40 2>$tempfile
retval=$?
case $retval in
0)
PASSWORD=`cat $tempfile`
VSFTPPASS=$PASSWORD
;;
1)
echo "Cancel pressed."
exit 0 ;;
255)
if test -s $tempfile ; then
cat $tempfile
else
exit 0
echo "ESC pressed."
fi
;;
esac
dialog --title "Credentials" --msgbox "Here is what I am using: \n Username: $VSFTPUSER \n Password: $VSFTPPASS" 10 50
##backup the existing config
DATE=`date '+%Y.%m.%d-%H:%M'`
#backup user file
cp /etc/vsftpd/vsftpd_users.txt /etc/vsftpd/vsftpd_users.txt.$DATE
#backup db file
cp /etc/vsftpd/vsftpd_users.db /etc/vsftpd/vsftpd_users.db.$DATE
##Append new user and password to the users file
echo "$VSFTPUSER" >> $USERSFILE
echo "$VSFTPPASS" >> $USERSFILE
#Creating the ftp users database
echo "Creating the FTP user database"
db42_load -T -t hash -f /etc/vsftpd/vsftpd_users.txt /etc/vsftpd/vsftpd_users.db
sleep 2
#make directory for the user
echo "Creating directory for $VSFTPUSER"
mkdir /ftp/$VSFTPUSER
if [ "$?" = "0" ]
then
echo "Directory created successfully"
sleep 2
else
echo "ERROR: Could not create directory, exiting"
exit 1
fi
#Change ownership
echo "Changing ownership of directory for the vsftp user"
chown -R virtualftp:virtualftp /ftp/$VSFTPUSER
if [ "$?" = "0" ]
then
echo "Ownership created successfully"
sleep 1
else
echo "ERROR: Could not change ownership, exiting"
exit 1
fi
if [ "$?" = "0" ]
then
dialog --title "Add user" --msgbox "User added successfully." 10 50
# Mark script with current date and time
touch ~/.backup
else
# Backup failed, display error log
dialog --title "Backup" --msgbox "User add failed-- Press
<Enter>
to see error log." 10 50
dialog --title "Error Log" --textbox /tmp/ERRORS$$ 22 72
fi
fi
rm -f /tmp/ERRORS$$
clear
4. make it executable (from the command line):
sudo chmod +x /usr/bin/vsftp_add.sh
5. run it:
sudo /usr/bin/vsftp_add.sh
6. Follow the steps onscreen.
(* You need to have the program called dialog installed on the system)