Link from: http://www.5ilinux.com/blog/archives/000091.html
1. First, create the corresponding user and user group
Groupadd-G 5500 ftpgroup
Adduser-u 5500-S/bin/false-D/bin/null-c "ProFTPD user"-G ftpgroup ftpuser
2. operate databases
MySQL mysql-uroot-ppassword
Create Database ftpdb
Grant select, update on ftpdb. * to ProFTPD @ localhost identified by 'Password' use ftpdb
Create Table 'ftpgroup '(
'Groupname' varchar (16) not null default '',
'Gid' smallint (6) Not null default '20140901 ',
'Members 'varchar (16) not null default '',
Key 'groupname' ('groupname ')
) Type = MyISAM comment = 'proftp group table ';
Insert into 'ftpgroup' values ('ftpgroup', 5500, 'ftpuser ');
Create Table 'ftpquotalimits '(
'Name' varchar (30) default null,
'Quota _ type' Enum ('user', 'group', 'class', 'all') not null default 'user ',
'Per _ session' Enum ('false', 'true') not null default 'false ',
'Limit _ type' Enum ('soft ', 'hard') not null default 'soft ',
'Bytes _ in_avail 'float not null default '0 ',
'Bytes _ out_avail 'float not null default '0 ',
'Bytes _ xfer_avail 'float not null default '0 ',
'Files _ in_avail 'int (10) unsigned not null default '0 ',
'Files _ out_avail 'int (10) unsigned not null default '0 ',
'Files _ xfer_avail 'int (10) unsigned not null default '0'
) Type = MyISAM;
Create Table 'ftpquotatallies '(
'Name' varchar (30) not null default '',
'Quota _ type' Enum ('user', 'group', 'class', 'all') not null default 'user ',
'Bytes _ in_used' float not null default '0 ',
'Bytes _ out_used' float not null default '0 ',
'Bytes _ xfer_used' float not null default '0 ',
'Files _ in_used' int (10) unsigned not null default '0 ',
'Files _ out_used' int (10) unsigned not null default '0 ',
'Files _ xfer_used' int (10) unsigned not null default '0'
) Type = MyISAM;
Create Table 'ftpuser '(
'Id' int (10) unsigned not null auto_increment,
'Userid' varchar (32) not null default '',
'Passwd' varchar (32) not null default '',
'Uid' smallint (6) Not null default '123 ',
'Gid' smallint (6) Not null default '20140901 ',
'Homedir' varchar (255) not null default '',
'Shell 'varchar (16) not null default'/sbin/nologin ',
'Count' int (11) not null default '0 ',
'Accessed' datetime not null default '2017-00-00 00:00:00 ',
'Modified' datetime not null default '2017-00-00 00:00:00 ',
Primary Key ('id ')
) Type = MyISAM comment = 'proftp user table ';
Note that you can enter the user name and password of your database as needed. If you are not familiar with database operations, you can use phpMyAdmin.
3. Configure the ProFTP File
Servername "Frank's FTP server" servertype standalone defaultserver onport 21
Umask 022
Maxinstances 30
Maxloginattempts 3
User nobody
Group nobody
Maxhostsperuser 1 "sorry, you may not connect more than one time ."
Maxclientsperuser 2 "only one such user at a time ."
Maxclientsperhost 3 "sorry, you may not connect more than one time ."
Rootlogin off
Requirevalidshell off
Timeoutstalled 10
Maxclients 10
Allowforeignaddress on
Allowstorerestart on
Serverident off
Defaultroot ~ Ftpgroup
Sqlauthtypes backend plaintext
# Backend indicates that the user authentication method is MySQL database authentication method
# Plaintext indicates the plaintext authentication method, which is the first method to be used.
Sqlauthenticate users * Groups *
# Databasename @ host database_user user_password
Sqlconnectinfo ftpdb @ localhost ProFTPD Password
Sqluserinfo ftpuser userid passwd uid GID homedir Shell
Sqlgroupinfo ftpgroup groupname GID members
Sqlhomedirondemand on
# If the user's main directory does not exist, the system creates a directory based on the value of the homedir field in the user data table.
# Update count every time user logs in
Sqllog pass updatecount
Sqlnamedquery updatecount Update "Count = count + 1, accessed = now () Where userid = '% U'" ftpuser
# Update modified everytime user uploads or deletes a file
Sqllog STOR, Dele modified
Sqlnamedquery modified Update "modified = now () Where userid = '% U'" ftpuser
Quotaengine on
Quotadirectorytally on
Quotadisplayunits MB
Quotashowquotas on
Quotalog "/var/log/quota"
Sqlnamedquery get-quota-limit select "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avai
L, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail from ftpquotalimits where name = '% {0 }'
And quota_type = '% {1 }'"
Sqlnamedquery get-quota-Tally select "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_ I
N_used, files_out_used, files_xfer_used from ftpquotatallies where name = '% {0}' and quota_type = '% {1 }'"
Sqlnamedquery Update-quota-Tally Update "bytes_in_used = bytes_in_used + % {0}, bytes_out_used = bytes_out_used
+ % {1}, bytes_xfer_used = bytes_xfer_used + % {2}, files_in_used = files_in_used + % {3}, files_out_used = files _
Out_used + % {4}, files_xfer_used = files_xfer_used + % {5} Where name = '% {6}' and quota_type = '% {7}' "ftpquota
Tallies
Sqlnamedquery insert-quota-Tally Insert "% {0}, % {1}, % {2}, % {3}, % {4}, % {5 }, % {6}, % {7} "ftpquotatallies
Quotalimittable SQL:/get-quota-Limit
Quotatallytable SQL:/get-quota-Tally/update-quota-Tally/insert-quota-tally
OK, that's easy. Restart the ProFTP service to use ProFTP + MySQL + quota.
We can add a virtual user to the database ftpuser,
Insert into 'ftpuser' values (1, 'test', 'ftpasswd', 5500,550 0, '/home/test','/sbin/nologin ');
You can directly add a user in phpMyAdmin. I believe you don't need to learn how to add it :)
If you want to set quota, you only need to set it in the ftpquotalimits table. The parameters in this table represent:
Quotalimits table name:-User Account
Quota type:-user, group, class, all (we use user)
Per_session:-True or false (we use True)
Limit_type:-Hard limit or soft limit (we usually use hard limit)
Bytes_in_avail:-number of bytes allowed for upload
Bytes_out_avail:-number of bytes that can be downloaded
Bytes_xfer_avail:-number of bytes allowed for transmission (including upload/download)
Files_in_avail:-number of files that can be uploaded
Files_out_avail:-number of files that can be downloaded
Files_xfer_avail:-number of files that can be transferred (including upload/download)
To be honest, I used the MySQL and quota modules to verify the user and set the disk quota, but I still think it is not perfect, because in this method, the database table does not have the corresponding permission field, therefore, the permissions of the corresponding user must be controlled by the actual user, that is, the UID and GID corresponding to MySQL. That day, if the MySQL database can also have full control of permissions.