Vsftpd + MySQL creates virtual users under Debian Linux

Source: Internet
Author: User
Tags crypt
The following articles mainly describe the specific practices of vsftpd + MySQL virtual users in Debian Linux. I saw the information about vsftpd + MySQL virtual users in Debian Linux on the relevant website two days ago, let's share it with you. Today, I had nothing to do with ftp. The reason is very simple: to put what I can see elsewhere

The following articles mainly describe the specific practices of vsftpd + MySQL virtual users in Debian Linux. I saw information about vsftpd + MySQL virtual users in Debian Linux on the relevant website two days ago, I think it's good. I just want to share it with you. Today, I had nothing to do with ftp. The reason is very simple: to put what I can see elsewhere

The following articles mainly describe the specific practices of vsftpd + MySQL virtual users in Debian Linux. I saw information about vsftpd + MySQL virtual users in Debian Linux on the relevant website two days ago, I think it's good. I just want to share it with you.

Today, I had nothing to do with ftp. The reason is very simple: to put the good stuff that can be seen elsewhere on my machine, hey! It is not easy to select an ftp server in linux. After a bit of thinking, I chose vsftpd, the reason is that it is known as the safest ftp server in linux, and there are still many large websites that use it as a server (this makes it easy to use :)).

In order to prevent others from peeking at my password and logging on to my machine, I hate the fact that there are so many users in the system (like displaying my own hands ), therefore, I decided to use virtual users because MySQL (the best combination with PHP) is installed in the machine ), so I want to put vsftpd + MySQL virtual user data in MySQL (the best combination with PHP). Well, let's get started here. Next, let's get started!

Step 1:

Install vsftpd

Apt-get install vsftpd (Debian is awesome !)

The system automatically generates a configuration file and an ftp user for anonymous users. vsftpd uses pam to verify virtual users because vsftpd + MySQL virtual user information is stored in the database, therefore, we also need a local user who can read the database content and set its local directory:

 
 
  1. #mkdir /var/ftp
  2. #useradd -d ftpguest /var/ftp
  3. #chown ftpguest.nogroup /var/ftp

Step 2: Install MySQL (the best combination with PHP)

Apt-get install MySQL (the best combination with PHP)-server MySQL (the best combination with PHP)-clent

Create a database and add users

 
 
  1. # MySQL (the best combination with PHP)-p MySQL (the best combination with PHP)> create ftpu;
  2. MySQL (best combination with PHP)> use ftpu;
  3. MySQL (best combination with PHP)> create table user (name char (20) binary, passwd char (20) binary );
  4. MySQL (best combination with PHP)> insert into user (name, passwd) values ('test1', password ('20140901 '));
  5. MySQL (best combination with PHP)> insert into user (name, passwd) values ('test2', password ('20140901 '));
  6. MySQL (best combination with PHP)> quit
  7. Enable ftpguest to access ftpu and table user:
  8. # MySQL (the best combination with PHP)-u root MySQL (the best combination with PHP)
    -P MySQL (the best combination with PHP)> grant select on ftpu. user to ftpguest @ localhost identified by '123 ';

MySQL (best combination with PHP)> quit

Step 3: Because vsftpd is verified by PAM

Therefore, we also need a MySQL (the best combination with PHP) package verified by PAM. In Debian, it is called libpam-MySQL (the best combination with PHP)

Apt-get install libpam-MySQL (best combination with PHP)

Enable pam verification For vsftpd:

 
 
  1. #vi /etc/pam.d/vsftpd

Comment out the previous content and add the following content:

Auth required pam_MySQL (best combination with PHP). so user = ftpguest passwd = 123456 host = localhost db = ftpu table = user usercolumn = name passwdcolumn = passwd crypt = 2

Account required pam_MySQL (best combination with PHP). so user = ftpguest passwd = 123456 host = localhost db = ftpu table = user usercolumn = name passwdcolumn = passwd crypt = 2

The above content should be clear. The crypt = 2 indicates something that has passed the password () secret of MySQL (the best combination with PHP!

Step 4: Modify the vsftpd. conf file

 
 
  1. #vi /etc/vsftpd.conf

Join:

 
 
  1. Uest_enable = yes
  2. Guest_username = ftpguest
  3. # Indicates that ftpguest is a virtual user of vsftp.
  4. Virtual_use_local_privs = yes

Vsftpd + MySQL virtual users have the same permissions as local users

 
 
  1. write_enable=yes
  2. anon_upload_enable=yes
  3. anon_other_write_enable=yes

Allows virtual users to upload, modify, and delete files.

 
 
  1. chroot_local_user=yes

Virtual users can only access their own directories.

 
 
  1. anonymous_enable=no
  2. local_enable=yes

Disable Anonymous user access and enable local user access

Step 5:

The fourth step has already been completed, but I thought about it later. No, if every upload is different, how can I manage the directory in a mess, can I create a directory for each vsftpd + MySQL virtual user? For example, place the files uploaded by music users in ~ /Music, put the File Uploaded By the doc user in ~ /What about doc?

Yes! Of course. How can I do this?

First, add two vsftpd + MySQL virtual users (music and doc) to the database:

 
 
  1. #mkdir /etc/vsftpd_user_conf
  2. #cd /etc/vsftpd_user_conf
  3. #touch music
  4. #echo "local_root=/home/username/music" > music
  5. #touch doc
  6. #echo "local_root=/home/username/doc" > doc
  7. #mkdir /home/username/music
  8. #chown ftpguest.nogroup /home/username/music
  9. #chmod 600 /home/username/music
  10. #chown ftpguest.nogroup /home/username/doc
  11. #chmod 600 /home/username/doc

Add user_config_dir =/etc/vsftpd_user_conf to vsftpd. conf?

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.