How to add FTP user - script

- After installing FTP server -
check my HowTo post - How to install FTP server.
you want to get the next script for add your FTP users easily.

Create a new script:
# vi /usr/bin/add_ftp_user
and copy the next lines to it
#!/bin/bash
# Script to add a user to Linux system

if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi

usermod -g proftpd $username
save and run the command:
# chmod +x /usr/bin/add_ftp_user

For add a new user just run the script
# add_ftp_user
enter a user name and password
and that's it.

Enjoy


No comments:

Post a Comment