Vsftpd + pam + mysql for ftp Construction

Source: Internet
Author: User
Tags crypt ftp client

 

1. Install the required program 1. Install the development environment and mysql database in advance;

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/1Z00a648-0.png "/>

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/1Z0095U0-1.png "/>

Configure the yum server. repo File
 
 
  1. [Root @ localhost yum. repos. d] # cd
  2. [Root @ localhost ~] # Mkdir/mnt/cdrom
  3. [Root @ localhost ~] # Mount/dev/cdrom/mnt/cdrom/
  4. // Mount the image above to use yum
  5. [Root @ localhost ~] # Cd/etc/yum. repos. d/
  6. [Root @ localhost yum. repos. d] # vim server. repo
  7. // Add content
  8. [Base]
  9. Name = Instructor Server Repository
  10. Baseurl = file: // mnt/cdrom/Server // The image here is locally mounted
  11. Gpgcheck = 0
  12. [Root @ localhost ~] # Yum-y install mysql-server mysql-devel
  13. [Root @ localhost ~] # Service mysqld start
  14. [Root @ localhost ~] # Yum-y groupinstall "Development Tools" "Development Libraries"
2. Install pam_mysql-0.7RC1 here I prepared in advance compressed package closer to linux, you can download this compressed package online. Follow these steps:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/1Z0091537-2.png "/>

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201304/230716381.png "/>

Then turn it off. Return to linux. Ls. You can see that the file is already in the home directory.
 
 
  1. [root@localhost ~]# tar zxvf pam_mysql-0.7RC1.tar.gz  
  2. [root@localhost ~]# cd pam_mysql-0.7RC1  
  3. [root@localhost pam_mysql-0.7RC1] # ./configure --with-mysql=/usr --with-openssl  
  4. [root@localhost pam_mysql-0.7RC1] # make  
  5. [root@localhost pam_mysql-0.7RC1] # make install  
3. Install vsftpd
 
 
  1. [Root @ localhost pam_mysql-0.7RC1] # yum-y install vsftpd
  2. // Note: Check whether the selinux service is enabled at this time, because its activation will affect the later services.
  3. [Root @ localhost ~] # GetenforceEnforcing
  4. [Root @ localhost ~] # Setenforce 0
  5. [Root @ localhost ~] # GetenforcePermissive
  6. // Of course. Here, we also need to replace selinux = enforcing with SELINUX = permissive in vim/etc/SELINUX/config.
2. Create a virtual user account 1. Prepare the database and related tables. First, make sure that the mysql service is started properly. Then, you can create a database to store virtual users as needed. Here, you can create a vsftpd database.
 
 
  1. mysql> create database vsftpd;  
  2.    
  3. mysql> grant select on vsftpd.* to vsftpd@localhost identified by 'doubao';  
  4. mysql> grant select on vsftpd.* to vsftpd@127.0.0.1 identified by 'doubao';  
  5. mysql> flush privileges;  
  6.    
  7. mysql> use vsftpd;  
  8. mysql> create table users (  
  9.     -> id int AUTO_INCREMENT NOT NULL,  
  10.     -> name char(20) binary NOT NULL,  
  11.     -> password char(48) binary NOT NULL,  
  12.     -> primary key(id)  
  13.     -> );  
2. Add a test virtual user to add the user as needed. It should be noted that the password is stored in plaintext format here, because the password of pam_mysql () the function may be different from the MySQL password () function.
 
 
  1. mysql> insert into users(name,password) values('tom','magedu');  
  2. mysql> insert into users(name,password) values('jerry','magedu');  
  3. mysql>\q  
3. Configure vsftpd 1. Create required documents for pam Authentication
 
 
  1. [Root @ localhost ~] # Vi/etc/pam. d/vsftpd. mysql
  2. Add the following two lines
  3. Auth required/lib/security/pam_mysql.so user = vsftpd passwd = doubao host = localhost db = vsftpd table = users usercolumn = name passwdcolumn = password crypt = 0
  4. Account required/lib/security/pam_mysql.so user = vsftpd passwd = doubao host = localhost db = vsftpd table = users usercolumn = name passwdcolumn = password crypt = 0
2. modify the configuration file of vsftpd to adapt to the System user and corresponding directory for establishing virtual user ing through mysql authentication.
 
 
  1. [Root @ localhost ~] # Useradd-s/sbin/nologin-d/var/ftproot vuser
  2. [Root @ localhost ~] # Chmod go + rx/var/ftproot
  3. // Make sure that the following options are enabled in/etc/vsftpd. conf.
  4. Anonymous_enable = YES
  5. Local_enable = YES
  6. Write_enable = YES
  7. Anon_upload_enable = NO
  8. Anon_mkdir_write_enable = NO
  9. Chroot_local_user = YES
  10. // Add the following options
  11. Guest_enable = YES
  12. Guest_username = vuser
  13. // Make sure that the value of the pam_service_name option is as follows:
  14. Pam_service_name = vsftpd. mysql
4. Start the vsftpd service
 
 
  1. [Root @ localhost ~] # Service vsftpd start
  2. Starting vsftpd for vsftpd: [OK]
  3. [Root @ localhost ~] # Chkconfig vsftpd on
  4. // View port enabling status
  5. [Root @ localhost ~] # Netstat-tnlp | grep: 21
  6. Tcp 0 0 0.0.0.0: 21 0.0.0.0: * LISTEN 11336/vsftpd
Use a virtual user to log on and verify the configuration result. The following is a command test on the local machine. You can also use IE or FTP client tool to log on to other Windows boxes to verify the configuration result.

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201304/230800893.png "/>

 
 
  1. [root@localhost ~]# ftp localhost  

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/1Z0091U4-5.png "/>

5. Configure virtual users to have different access permissions. vsftpd provides a separate configuration file for each user in the configuration file directory to define their ftp service access permissions, the configuration file name of each virtual user is the same as that of the virtual user. The configuration file directory can be any unused directory. You only need to specify its path and name in vsftpd. conf. 1. Configure vsftpd as the configuration file directory for virtual users
 
 
  1. [Root @ localhost ~] # Vim/etc/vsftpd. conf
  2. // Add the following options
  3. User_config_dir =/etc/vsftpd/vusers_dir
2. Create the desired directory and provide the configuration file for the virtual user
 
 
  1. [root@localhost ~]# mkdir /etc/vsftpd/vusers_dir/  
  2. [root@localhost ~]# cd /etc/vsftpd/vusers_dir/  
  3. [root@localhost ~]# touch tom jerry  
3. Configure virtual user access permissions virtual users access vsftpd services through commands of anonymous users. For example, to allow the tom user to upload files, modify the/etc/vsftpd/vusers/tom file and add the following options. Anon_upload_enable = YES

Related Article

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.