How does ftp Implement User Authentication Based on mysql Databases and corresponding table fields?

Source: Internet
Author: User

Virtual User Logon mode: maps login users to the specified system account (/sbin/nologin) to access FTP resources, which ensures security.

1. Install the required Program

1. Install the development environment and mysql database

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image002 "border =" 0 "alt =" clip_image002 "width =" 630 "height =" 217 "src =" http://www.bkjia.com/uploads/allimg/131228/0153364402-0.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image004 "border =" 0 "alt =" clip_image004 "width =" 685 "height =" 199 "src =" http://www.bkjia.com/uploads/allimg/131228/01533B020-1.jpg "/>

2. Install the pam_mysql-0.7RCl module, because our pam by default does not support to verify the user account in mysql, so we have to install a plug-in for pam

650) this. width = 650; "style =" background-image: none; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image006 "border =" 0 "alt =" clip_image006 "width =" 698 "height =" 164 "src =" http://www.bkjia.com/uploads/allimg/131228/01533A645-2.jpg "/>

3. Unzip the pam_mysql-0.7RC1 Module

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image008 "border =" 0 "alt =" clip_image008 "width =" 900 "height =" 102 "src =" http://www.bkjia.com/uploads/allimg/131228/01533A320-3.jpg "/>

4. Start mysql

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image010 "border =" 0 "alt =" clip_image010 "width =" 698 "height =" 88 "src =" http://www.bkjia.com/uploads/allimg/131228/0153362K3-4.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image012 "border =" 0 "alt =" clip_image012 "width =" 570 "height =" 88 "src =" http://www.bkjia.com/uploads/allimg/131228/01533632H-5.jpg "/>

6. view the mysql list

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image014 "border =" 0 "alt =" clip_image014 "width =" 501 "height =" 247 "src =" http://www.bkjia.com/uploads/allimg/131228/01533634I-6.jpg "/>

7. view the mysql package and verify the mysql installation location

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image016 "border =" 0 "alt =" clip_image016 "width =" 488 "height =" 327 "src =" http://www.bkjia.com/uploads/allimg/131228/0153362L1-7.jpg "/>

8. Tell mysql where to install

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image018 "border =" 0 "alt =" clip_image018 "width =" 728 "height =" 248 "src =" http://www.bkjia.com/uploads/allimg/131228/01533A427-8.jpg "/>

9. make

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image020 "border =" 0 "alt =" clip_image020 "width =" 838 "height =" 309 "src =" http://www.bkjia.com/uploads/allimg/131228/0153364303-9.jpg "/>

10. Install make

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image022 "border =" 0 "alt =" clip_image022 "width =" 757 "height =" 441 "src =" http://www.bkjia.com/uploads/allimg/131228/0153363339-10.jpg "/>

11. Check whether pam_mysql exists.

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image024 "border =" 0 "alt =" clip_image024 "width =" 892 "height =" 200 "src =" http://www.bkjia.com/uploads/allimg/131228/0153361L3-11.jpg "/>

2. Create a virtual user account

1. Connect to the database mysql to create a database and a table

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image026 "border =" 0 "alt =" clip_image026 "width =" 652 "height =" 317 "src =" http://www.bkjia.com/uploads/allimg/131228/0153364418-12.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image028 "border =" 0 "alt =" clip_image028 "width =" 659 "height =" 162 "src =" http://www.bkjia.com/uploads/allimg/131228/0153364461-13.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image030 "border =" 0 "alt =" clip_image030 "width =" 639 "height =" 144 "src =" http://www.bkjia.com/uploads/allimg/131228/01533B5K-14.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image032 "border =" 0 "alt =" clip_image032 "width =" 621 "height =" 243 "src =" http://www.bkjia.com/uploads/allimg/131228/01533B461-15.jpg "/>

2. Test the vsftpd Database

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image034 "border =" 0 "alt =" clip_image034 "width =" 574 "height =" 488 "src =" http://www.bkjia.com/uploads/allimg/131228/0153361008-16.jpg "/>

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image036 "border =" 0 "alt =" clip_image036 "width =" 409 "height =" 187 "src =" http://www.bkjia.com/uploads/allimg/131228/01533B5F-17.jpg "/>

3. Create documents required for pam Authentication

Edit the configuration file vim/etc/pam. d/vsftpd. mysql

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image038 "border =" 0 "alt =" clip_image038 "width =" 751 "height =" 96 "src =" http://www.bkjia.com/uploads/allimg/131228/0153361N2-18.jpg "/>

The main purpose of auth is to authenticate. auth required indicates that this requirement must be met. First, check whether the account combination is invalid and whether the account has expired.

4. Create a user

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image040 "border =" 0 "alt =" clip_image040 "width =" 841 "height =" 100 "src =" http://www.bkjia.com/uploads/allimg/131228/0153362354-19.jpg "/>

5. Modify the vsftpd configuration file vim/etc/vsftpd. conf.

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image042 "border =" 0 "alt =" clip_image042 "width =" 530 "height =" 256 "src =" http://www.bkjia.com/uploads/allimg/131228/01533644K-20.jpg "/>

6. Restart the service and verify that the virtual user can log on to upload and download files.

Service vsftpd restart service

Cp/etc/fstab/var/ftproot/copy/etc/fstab home directory/var/ftproot/

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image044 "border =" 0 "alt =" clip_image044 "width =" 546 "height =" 583 "src =" http://www.bkjia.com/uploads/allimg/131228/01533BG4-21.jpg "/>

Note: commands of virtual users are matched by commands of anonymous users. All users are mapped to a user named vuser. As long as we prohibit virtual users from uploading, this means that no virtual user can upload data.

Iii. Specific instances

Can different virtual users be defined to use different permissions for configuration? For example, tom cannot upload or download files, but jerry can. This is not acceptable, because all virtual users must be mapped to the same user account, and there is no way to establish a one-to-one ing relationship between them, but they can have different permissions. How can this problem be solved? You only need to add a command to ftp.

We define other functions that allow tom to download files but not upload files. jerry can upload files, download files, and create directories.

1. Edit the configuration file vim/etc/vsftpd. conf.

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image046 "border =" 0 "alt =" clip_image046 "width =" 672 "height =" 44 "src =" http://www.bkjia.com/uploads/allimg/131228/01533A3a-22.jpg "/>

2. Create the required directories and files

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image048 "border =" 0 "alt =" clip_image048 "width =" 673 "height =" 69 "src =" http://www.bkjia.com/uploads/allimg/131228/01533B149-23.jpg "/>

The content of the vim tom editing file is as follows:

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image050 "border =" 0 "alt =" clip_image050 "width =" 497 "height =" 56 "src =" http://www.bkjia.com/uploads/allimg/131228/01533BM3-24.jpg "/>

The content of the file edited by vim jerry is as follows:

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image052 "border =" 0 "alt =" clip_image052 "width =" 579 "height =" 81 "src =" http://www.bkjia.com/uploads/allimg/131228/01533631F-25.jpg "/>

3. test and verification

First test the user tom

650) this. width = 650; "style =" background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image054 "border =" 0 "alt =" clip_image054 "width =" 530 "height =" 422 "src =" http://www.bkjia.com/uploads/allimg/131228/0153361432-26.jpg "/>

Test user jerry

650) this. width = 650; "style =" background-image: none; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px; border-right -: "title =" clip_image056 "border =" 0 "alt =" clip_image056 "width =" 526 "height =" 391 "src =" http://www.bkjia.com/uploads/allimg/131228/0153363Z2-27.jpg "/>

This is how to implement User Authentication Based on mysql Databases and corresponding table fields,

From the above content, we can see that it is easy to manage virtual users in the mysql database?

This article is from the "show_only" blog, please be sure to keep this source http://10240214.blog.51cto.com/6634068/1182257

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.