Use Pureftpd for FTP permission and Disk Quota Management

Source: Internet
Author: User
Tags socket error

PureftpdIt is a fast, high-quality, and fully functional ftp server. The most important thing is that it supports setting the Default Client encoding. For how to use Pureftpd to manage FTP permissions and disk quotas, see the following.

We use Pure-ftpd as the tool.

Install

Pure-ftpd is a mature ftp tool. apt-get already has a good package. We can install it easily through apt-get directly.

Apt-get install pure-ftpd-mysql

Configuration

Create a database in the database. Use the previous hosting database. Use the following statement to create a table:

Create table users (

User varchar (16) not null default '',

Status enum ('0', '1') not null default '0 ',

Password varchar (64) not null default '',

Uid varchar (11) not null default '-1 ',

Gid varchar (11) not null default '-1 ',

Dir varchar (128) not null default '',

ULBandwidth smallint (5) not null default '0 ',

DLBandwidth smallint (5) not null default '0 ',

Comment tinytext not null,

Ipaccess varchar (15) not null default '*',

QuotaSize smallint (5) not null default '0 ',

QuotaFiles int (11) not null default 0,

Primary key (User ),

Unique key User (User)

) TYPE = MyISAM;

This table is used to store ftp user information.

Then, we need to modify the pure-ftpd-mysql configuration file to tell the pure-ftpd database information.

Assume that you have configured mysql and have an available account.

Vim/etc/pure-ftpd/db/mysql. conf

Put the following configuration

# Modify account information as needed

MYSQLServer 127.0.0.1

MYSQLPort 3306

MYSQLSocket/var/run/mysqld. sock

MYSQLUser easy

MYSQLPassword ******

MYSQLDatabase hosting

# Encryption Method

MYSQLCrypt md5

# SQL statement for data retrieval

# User authorization

MYSQLGetPW SELECT Password FROM users WHERE User = "\ L"

MYSQLGetUID SELECT Uid FROM users WHERE User = "\ L"

MYSQLGetGID SELECT Gid FROM users WHERE User = "\ L"

MYSQLGetDir SELECT Dir FROM users WHERE User = "\ L"

# File size and quantity restrictions

MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User = "\ L"

MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User = "\ L"

# Upstream and downstream bandwidth restrictions

MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User = "\ L"

MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User = "\ L"

In this way, pure-ftpd will know how to fetch data from mysql.

To obtain the GID and UID shown above, we need to create a virtual account for ftp. all FTP users share the UID and GID of this virtual account, instead of creating system users for each FTP user.

Groupadd-g 2001 ftpgroup

Useradd-u 2001-s/bin/false-d/bin/null-c "pureftpd user"-g ftpgroup ftpuser

We have created an ftpgroup group with GID 2001 and an ftpuser with UID 2001. now you can add data to the data table. the unit of QuotaSize is M, and the Directory points to the same path in mod-myvhost.

Then, we lock the user in his own directory and do not allow him to access others' directories through ftp:

Echo yes>/etc/pure-ftpd/conf/ChrootEveryone

Automatically creates a directory when the specified directory does not exist.

Echo yes>/etc/pure-ftpd/conf/CreateHomeDir

Setting complete. Restart pure-ftpd.

/Etc/init. d/pure-ftpd-mysql restart

All configurations are complete. Let's upload the file and try again.

Login successful, the file upload prompt does not have permission. This is caused by/data0/myapphost attribute setting. Change the entire directory to ftpuser.

Chown-R ftpuser: ftpgroup/data0/myapphost

After modifying the attributes, you can upload files. Try the following quota:

Error:> [22:47:12] The data socket cannot be written. Socket error = #10054.

[22:47:12] 550-Quota exceeded: abc.zip won't be saved

550-6 files used (120%)-authorized: 5 files

550 6974 Kbytes used (681%)-authorized: 1024 Kb

Error:> [22:47:12] The requested operation was not executed (for example, the file or directory is not found and cannot be accessed ).

Error:> [22:47:43] The data socket cannot be written. Socket error = #10054.

[22:47:43] 550-Quota exceeded: abc.zip won't be saved

550-4 files used (80%)-authorized: 5 files

550 3954 Kbytes used (386%)-authorized: 1024 Kb

Error:> [22:47:43] The requested operation was not executed (for example, the file or directory is not found and cannot be accessed ).

The error message shows that the quota has taken effect. After the configuration is modified, the logged-on ftp user needs to log on again before the quota takes effect.

Summary

So far, we have completed the basic functions of a single-server application management platform, and added a web management front-end for applying for applications and activating accounts. The entire platform can be put into use.

Through the introduction and analysis in this article, we have a clear understanding of the specific methods for managing FTP permissions and disk quotas using Pureftpd. I hope this article will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.