Using PROFTPD to build FTP server and configuration method _ftp server in Linux

Source: Internet
Author: User
Tags anonymous ftp login mysql manual disk usage

First PROFTPD is an open source software, its official address is http://www.proftpd.org, the current highest version is: 1.3.1 (not stable version), stable version is 1.3.0, download file for proftpd-1.3.0a.tar.gz

I downloaded the 1.3.0, upload it to the server and install it in the usual way.

TAR-ZXVF proftpd-1.3.0a.tar.gz
CD proftpd*
./configure--PREFIX=/USR/LOCAL/PROFTPD
Make
Make install

Setup is complete! Next is configuration.

Set up a: Random start service, sbin/proftpd files copied to the/etc/rc.d/rc.local folder, to enable automatic boot.
Set two: Configuration file in etc/proftpd.conf, configuration file description as follows:

ServerName "ProFTPD Default Installation"
ServerType Standalone
Defaultserver on

Respectively: Server name, service type, and default service state!
After the service port AH what I will omit to say, said the most critical permission control section.

# Set the user and group under which the server would run.
User Nobody
Group Nogroup

Look at the above: what users and what groups to run the service.

Change to your existing group and users, here for administrative convenience and security considerations, it is recommended to create a new FTP group and FTP users.
# to cause every FTP user to be ' jailed ' (chrooted) into their home
# directory, uncomment this line.
#DefaultRoot ~
Whether to allow users to enter the user's home directory, note: But apply/home substitution
# Normally, we want files to be overwriteable.
AllowOverwrite on
Whether you have the right to override
# A Basic Anonymous configuration, no upload directories. If you don't
# want anonymous users, simply delete this entire section.
User FTP
Group FTP
# We want clients to is able to login with "anonymous" as "FTP"
Useralias Anonymous FTP
# Limit The maximum number of anonymous logins
MaxClients 10
# We want ' welcome.msg ' displayed at login, and '. Message ' displayed
# in each newly chdired directory.
Displaylogin welcome.msg
Displayfirstchdir. Message
# Limit WRITE everywhere in the anonymous chroot
Denyall

This part of the definition of anonymous users is actually very simple.

Unable to start, the following error resolution appears

[Root@new-host sbin]#./proftpd
-IPv4 getaddrinfo ' new-host ' error:name or service not known
-Warning:unable to determine IP address of ' new-host '
-Error:no Valid servers configured
-Fatal:error processing configuration file '/usr/local/proftpd/etc/proftpd.conf '

The reason is that the IP address cannot be bound.

Add the following sentence to the configuration file:

Defaultaddress 192.168.8.105

Then restart the service!

Then I thought it was over,
But look to know if I want to add a new FTP user is actually a very troublesome thing, because the account is directly related to the system account, unsafe and bad operation, our goal is to make like a virtual host service provider that ftp!

Next, need a module of support to http://www.castaglia.org/proftpd/to see the Proftpd-mod-quotatab module, note the following sentence:

Note:mod_quotatab became part of the offical ProFTPD source distribution in 1.2.10rc1. If using a version of ProFTPD later than that, for use the Mod_quotatab already included, as it'll be most up-to-date .

We download the 1.3 version has been supported to do this thing, the main compile installation when the Mod_quotatab open up on it, and then recompile!

Prerequisite: Verify that you have installed and can run the MySQL properly, otherwise the work behind is meaningless!

Recompile:

./configure--prefix=/usr/local/proftpd--with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql-- With-includes=/usr/include/mysql--with-libraries=/usr/lib/mysql

Note According to your Linux system to find the appropriate include and Lib MySQL directory, the above examples of the relevant path is the default for most Linux systems, if your MySQL is compiled by source code installed, then the two directories are generally under the installation path.

There is information that: need to modify the contrib directory MOD_SQL_MYSQL.C files:

VI mod_sql_mysql.c

Find the #include line and change the mysql.h to the path of this file on your system, such as/usr/include/mysql/mysql.h
But I didn't do it, it's weird!

Then make
Make install

The same switch to the PROFTPD folder operation, the back of the more complex, I try to the level of university professors in simple language.
Configuring proftpd.conf Files

Edit/usr/local/proftpd/etc/proftpd.conf File:
Set disk quotas
#设置磁盘限额
Quotadirectorytally on
#设置磁盘容量显示时的单位
Quotadisplayunits "Kb"
#打开磁盘限额引擎
Quotaengine on
#设置磁盘限额日志文件
Quotalog "/usr/local/proftpd/var/quota"
#允许显示磁盘限额信息, FTP login to perform quote site Quota command to view current disk usage
Quotashowquotas on
Specify the database information used by the disk quota module
Add the following configuration to the proftpd.conf file:
Sqlnamedquery get-quota-limit SELECT "name, Quota_type, Per_session, Limit_type, Bytes_in_avail, \
Bytes_out_avail, Bytes_xfer_avail, Files_in_avail, Files_out_avail, files_xfer_avail from quotalimits \
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_in_used, files_out_used, files_xfer_used from quotatallies \
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} ' quotatallies
Sqlnamedquery insert-quota-tally Insert "%{0},%{1},%{2},%{3},%{4},%{5},%{6},%{7}" quotatallies
Quotalimittable Sql:/get-quota-limit
Quotatallytable sql:/get-quota-tally/update-quota-tally/insert-quota-tally

Many friends are about to ask: what are these things ah? totally don't understand! I don't understand!

Configure FTP users for MySQL database authentication method

Add the following configuration to the proftpd.conf file:
Sqlconnectinfo databasename@hostname:port userName Password
#databaseName是为proftpd建立的MySQL数据库的名字
#hostName是MySQL数据库所在的服务器的名字或ip地址
#port是MySQL服务所使用的端口
#userName是数据库的用户名
#password是数据库用户密码
Sqlauthtypes Backend PlainText
#Backend表示用户认证方式为MySQL数据库的认证方式
#Plaintext表示明文认证方式, top of the line for the first use of the way
Sqluserinfo ftpuser userid passwd uid GID homedir Shell
#指定ftp用户数据表的名字和其中的字段名, the table name is customizable and the field name is not changed.
Sqlgroupinfo Ftpgroup groupname GID members
#指定ftp用户组数据表的名字和其中的字段名, the datasheet is optional and the field name is not changed.
Requirevalidshell off
#指定是否必须为FTP用户指定一个系统shell, off means not specified, on means must be specified. You should specify off for system security.
Sqlauthenticate Users Groups Usersetfast Groupsetfast
#校验数据表
Sqlhomedirondemand on
#如果用户主目录不存在, the system creates a new directory based on the value of the user's Homedir field in the user datasheet
Create FTP system users and Groups
Create an FTP user and group, and all other FTP users in the future are actually FTP via this system User:
Groupadd–g 2003 Ftpgroup
Useradd–u 2003–g ftpgroup–d/home Ftpuser
The above set up a named Ftpgroup FTP group, the group ID is 2003; an FTP user is established, the user ID is 2003, and the Ftpgroup group is added, and the user's home directory is/home
Then modify the/home and access permissions:
Chown–r Ftpuser.ftpgroup/home
chmod 644/home
644 the specific meaning, please check the relevant documents.
Then modify the proftpd.conf file, locate user and group, specify user as ftpuser,group as Ftpgroup, replace the original default value, otherwise, if the system does not have the original default value specified users and groups, PROFTPD cannot be started successfully.

Establish the FTP User authentication related table
Mysql–u Root
Use MySQL

Add a MySQL User: FTP
Add a database: PROFTPD
Please refer to the MySQL manual for specific instructions.
After you have finished building users and databases, log on to MySQL with the new user:

Mysql–u FTP
Use PROFTPD;
CREATE TABLE Ftpuser (userid text not null,passwd text not null,uid int not null,gid int not null,homedir TEXT) ;
UserID is the user name, passwd is the user password, UID is the user id,gid is the user's group Id,homedir is the user's home directory, Shell is the user's system shell.
CREATE table Ftpgroup (groupname text not null,gid SMALLINT not null,members text not NULL);
GroupName is a group name, and a GID is a group id,members is a member of a group, with multiple members, separated by commas.
The above set up a data table for FTP users and user groups.
Set up a disk quota data table
CREATE TABLE Quotalimits (
Name VARCHAR (30),
Quota_type ENUM ("User", "group", "class", "All") is not NULL,
Per_session ENUM ("false", "true") not NULL,
Limit_type ENUM ("soft", "hard") not NULL,
Bytes_in_avail FLOAT not NULL,
Bytes_out_avail FLOAT not NULL,
Bytes_xfer_avail FLOAT not NULL,
Files_in_avail INT UNSIGNED not NULL,
Files_out_avail INT UNSIGNED not NULL,
Files_xfer_avail INT UNSIGNED not NULL
);
CREATE TABLE Quotatallies (
Name VARCHAR not NULL,
Quota_type ENUM ("User", "group", "class", "All") is not NULL,
bytes_in_used FLOAT not NULL,
bytes_out_used FLOAT not NULL,
bytes_xfer_used FLOAT not NULL,
files_in_used INT UNSIGNED not NULL,
files_out_used INT UNSIGNED not NULL,
files_xfer_used INT UNSIGNED not NULL
);

The Quotalimits table above is the disk quota configuration information for the FTP user, and the Quotatallies table holds information about the changes in the user's disk quota.
Quotatallies tables are not required to be modified and are automatically recorded by the program
The following are the meanings of the fields in the Quotalimits table:
Identification of quota_type disk quotas
Bytes_in_avail upload the maximum number of bytes, is the FTP user space capacity
Bytes_out_avail Download Maximum bytes
Bytes_xfer_avail The maximum number of bytes of files that can be transferred (upload and download traffic)
Files_in_avail The total number of files uploaded
Files_out_avail The total number of files that can be downloaded from the server
Files_xfer_avail The total number of files that can be transferred (upload and download)

Data table Data Initialization

Once all the tables have been built, you can create an FTP user and insert a record in the Ftpuser table as follows:
INSERT into Ftpuser (userid, passwd, uid, GID, homedir, Shell) VALUES (' Shine ', password (' YourPassword '), ' 2003 ', ' 2003 ', '/home/shine ', ');
The above set up a new FTP user, user name is shine, password is yourpassword, can see password use MySQL system function password to encrypt, user ID and group ID are 2003, here casually fill, I filled in the same ID as the system User Ftpuser and System group Ftpgroup, I don't know if there will be any problems. /home/shine is the user's home directory and the user shell is empty.

If you want to apply more functionality, and set up a group of data tables, you also need to add records, but it must be noted that in the members of the field more than one member must be separated by commas.

INSERT into Ftpgroup VALUES (' Ftpgroup ', 2003, ' Ftpuser ');
The initial user disk quota information is set up below:
will have established Shine account number 50M space, can upload up to 500 files, file transfer flow of 512k, a total of only 2000 files, insert record as follows:
INSERT into Quotalimits (Name,quota_type,per_session,limit_type,bytes_in_avail,bytes_out_avail,bytes_xfer_avail, Files_in_avail,files_out_avail,files_xfer_avail) VALUES (' Shine ', ' user ', ' true ', ' soft ', ' 51200000 ', ' 0 ', ' 512000 ', ' 500 ', ' 0 ', ' 2000 ');
Run PROFTPD
Start the PROFTPD service by executing the following command:
/usr/local/proftpd/sbin/proftpd
Open a console input:
FTP Ftphostname
Enter user name: Shine
Enter User password: YourPassword
Execute after successful login:
Quote Site Quota
You can see the disk usage for this user.

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.