Virtual FTP Users + SSL
Updated: 11/18/2005
General Information
Running a FTP server is quite popular for sharing files over the Internet. But, the FTP protocol is not as secure as some may think. By default, each FTP user has a system shell account and when connecting to the FTP server, all usernames and passwords are transmitted in plaintext. That means anybody sniffing your packets can gain access to your FTP accounts. This guide is intended to provide a solution to both problems. Pure-ftpd with puredb allows you to have throttled FTP-only accounts and the ability to use SSL.Requirements
Installation
In order to have virtual user accounts, we need a database of some sort. You can compile pure-ftpd to work with MySQL, but we are going to use puredb because it was written specifically for use with pure-ftpd.|
# # # # |
cd /usr/ports/databases/puredb make install distclean cd /usr/ports/ftp/pure-ftpd make install distclean |
Configuration
Firse, we need to rename the configuration file and make an entry to rc.conf to make the daemon start.|
# # # |
cd /usr/local/etc mv pure-ftpd.conf.sample pure-ftpd.conf echo 'pureftpd_enable="YES"' >> /etc/rc.conf |
|
# nano -w pure-ftpd.conf ChrootEveryone yes PureDB /usr/local/etc/pureftpd.pdb Umask 177:077 AllowUserFXP no CreateHomeDir yes TLS 1 |
|
# # # # |
mkdir -p /etc/ssl/private openssl req -x509 -nodes -newkey rsa:1024 -keyout /etc/ssl/private/pure-ftpd.pem \ -out /etc/ssl/private/pure-ftpd.pem chmod 600 /etc/ssl/private/*.pem |
| # | /usr/local/etc/rc.d/pure-ftpd.sh start |
Managing Users
Now that pure-ftpd is up and running, it is time to create and manage our users. Virtual user information is created and modified with pure-pw and the info is authenticated against/usr/local/etc/pureftpd.passwd and the puredb in /usr/local/etc/pureftpd.pdb. Since the virtual users do not really exist system-wide, we need to create an actual user and group for filesystem read/write access. You could even use an existing user/group, but to completely isolate the ftp users, we will create new ones.|
# # # |
pw groupadd ftpgroup pw useradd ftpusers -c "Virtual FTP Users" -g ftpgroup -d /dev/null -s /sbin/nologin mkdir /usr/home/ftpusers |
|
# # # # # # # # |
pw useradd ftp -c "Anonymous FTP" -d /usr/home/ftpusers/ftp -s /sbin/nologin mkdir /usr/home/ftpusers/ftp mkdir /usr/home/ftpusers/ftp/incoming mkdir /usr/home/ftpusers/ftp/pub chown ftpusers:ftpgroup /usr/home/ftpusers/ftp chown ftp:ftpgroup /usr/home/ftpusers/ftp/* chmod 0755 /usr/home/ftpusers/ftp/incoming chmod 0555 /usr/home/ftpusers/ftp/pub |
|
# pure-pw useradd bob -u ftpusers -d /usr/home/ftpusers/bob -m Password: Enter it again: |
bob, has been created with the UID of ftpusers and the home directory of /usr/home/ftpusers/bob and this information is mirrored to /usr/local/etc/pureftpd.pdb with the -m flag. If you want bob to have access to the entire system directory, use the -D flag instead of -d. If you ever get errors about a user not being found, you can always fix that by creating the database with| # | pure-pw mkdb |
/usr/local/etc/pure-ftpd.conf to include UnixAuthentication, but the recommended way is to add your existing system accounts to pureftpd.passwd. This is recommended because their ftp access can then be throttled or managed.| # | pure-pwconvert >> /usr/local/etc/pureftpd.passwd |
| # | pure-pw usermod bob -n 10 -T 20 -m |
|
# pure-pw show bob Login : bob Password : $2a$07$2GsgzvrRTdAT9ld3bi.rPuIT1bfnfzJx1tqAn49uwHRPn3vfOEhUW UID : 1003 (ftpusers) GID : 1003 (ftpgroup) Directory : /home/ftpusers/bob/./ Full name : Download bandwidth : 0 Kb (unlimited) Upload bandwidth : 20 Kb (enabled) Max files : 10 (enabled) Max size : 0 Mb (unlimited) Ratio : 0:0 (unlimited:unlimited) Allowed local IPs : Denied local IPs : Allowed client IPs : Denied client IPs : Time restrictions : 0000-0000 (unlimited) Max sim sessions : 0 (unlimited) |
| # | pure-pw userdel bob -m |
| # | pure-pw |
Author: Jon LaBass
jon at bsdguides dot org