I am one of those who likes to innovate and learn new things, not long ago I had to install and configure an FTP server and I decided to do it differently than I always did.
In this case I opted for an FTP service with virtual users, users that will be stored in an encrypted file (username, password, settings, etc.), all with Pure FTPd.
Here I will show you how to do it… okay, let’s get started
First of all, specify that the commands in this tutorial are intended for distros like Debian or based on them, however if someone uses another distro on their server they must install the same packages and use the settings set below, the only thing that needs to change is the install command.
1. First we need to install Pure FTPd:
apt-get install pure-ftpd
The output will end something like this:
2. The service is already activated, but it's useless if we haven't configured it properly. Let's say we have a long but almost standard configuration file; it contains the usual things, establishing that anonymous users are not allowed, etc.
cd /etc/pure-ftpd/ && wget http://ftp.desdelinux.net/pure-ftpd.conf
3. Okay, let's assume our FTP folder is /var/www/ftp/ and we want to create a user who can upload information to the /var/www/ftp/sysadmin/ folder. Let's put the following in a terminal:
pure-pw useradd sysadmin -u 2001 -g 2001 -d /var/www/ftp/sysadmin/
This means the following:
pure-pw: Command used to manipulate Pure-FTPd users
useradd: We indicate that we will add a user
sysadmin: The user I want to create
-u 2001: UserID of that user
-g 2001: GroupID of that user
-d / var / www / ftp / sysadmin /: The folder that will be the home of that user, that is, where they will upload things
When you enter the previous line, it will ask you the password of that user.
4. Now you need to refresh the user database file. To do this, go to the /etc/pure-ftpd/ folder (cd /etc/pure-ftpd) and type the following in the terminal:
pure-pw mkdb
5. Now we must start Pure-FTPd, but specifying that we will use the virtual users file. First, let's stop the service:
/etc/init.d/pure-ftpd stop
Then we will make sure that it will not start by default normally:
chmod -x /etc/init.d/pure-ftpd
And now we start the service our way:
/usr/sbin/pure-ftpd -j -lpuredb:/etc/pure-ftpd/pureftpd.pdb
6. If you try using an application like FileZilla, you'll see that you can connect without problems with the created user; however, you won't be able to copy anything or create directories. This is because the folder /var/www/ftp/sysadmin/ (the user's home directory in this example) doesn't have the appropriate permissions. This can be fixed with:
chown -R 2001:2001 /var/www/ftp/sysadmin/
Remember, the Uid and Gid 2001 is that of the user we created, we created it with the command in the previous step 3
7. To stop the service, simply press [Ctrl]+[C] on the same terminal, or on another terminal do the following:
killall pure-ftpd
Now we will indicate that the service will start automatically with the system when the server starts, for this we modify the /etc/rc.local file and before the last line that says "exit 0" we put the command with which we start the FTP service:
/usr/sbin/pure-ftpd -j -lpuredb:/etc/pure-ftpd/pureftpd.pdb
In other words, it would look like this:
You can edit the file with nano, vi or your preferred editor, or if you prefer, copy and paste this command that will make your work easier:
perl -pi -e "s[exit 0][/usr/sbin/pure-ftpd -j -lpuredb:/etc/pure-ftpd/pureftpd.pdb]g" /etc/rc.local && echo "exit 0" >> /etc/rc.local
…yes yes… as you read, “facilitate” is a long command yes, but it is simply replacing text with perl and a harmless echo
8. Once this is done, restart the server and you will see that the pure-ftpd service is now started and ready to run
How to delete users?
As I mentioned before, the pure-pw command is what we need to manipulate users. To delete a user (for example, sysadmin), we would use the following:
cd /etc/pure-ftpd/
pure-pw userdel sysadmin
pure-pw mkdb
Remember that whenever you make a change to any user, you must regenerate the virtual database file of the users, it is located in / etc / pure-ftpd / and it is generated / updated with pure-pw mkdb
Anyway friends I think there is not much more to add, invite you to read the help of pure-pw because it allows us much more than the ones I showed you here (this is just a short and almost basic tutorial).
One or two years ago I was one of those who linked everything to OpenLDAP or MySQL, but over time I realized that so many connections to databases that are servers as such generate a consumption that many times we cannot afford, hence the use of completely viable alternatives such as using databases in files specific to the application, as is the case of the . pdb files of Pure-FTPd
Any doubt or question I will try to help as much as I can.
Greetings and… happy hacking!