Use Mysql to manage ftp users

Source: Internet
Author: User
Use Mysql to manage ftp user-Linux Enterprise Application-Linux server application information. The following is a detailed description. Use mysql to manage Vsftpd users.

1. Configure SMA to drag the software package into the linux. Software Package in the public directory.
First, use SMB or FTP to use the mysql package to upload it to linux.
Useradd-smb # create a local user smb
Smbpasswd-a smb # Add an smb User and set the password.
Service smb start # start the smb service
Then access: \ linux IP address on xp # Drag the software package in. The package name is pam_mysql.
Return to linux

2. decompress the package for compilation and installation.
Cd/home/smb
Tar zxvf pam_mysql-0.7RC1.tar.gz # Extract
Cd pam_mysql-0.7RC1 # Enter the directory after decompression.
./Configure -- with-openssl # pre-compilation Configuration
Make # compile the server program
Make install # install a program to compile

3. Configure mysql
Cd/usr/lib/security/
Cp pam_mysql.so/lib/security/# copy the executable program to/lib/security.
Service mysqld start # start the mysqld service. Note that there is a "d!

4. Create a database and table in mysql and insert a user name and password into the table.
Mysqladmin-u root-p password test Change password as Administrator
Note: --> if you are prompted to enter the password, press enter because no password is set before.
Mysql-u root-p log on to mysql
Create database chen; # Pay Attention to the plus points after the command at the end.
Use chen # Go To The database you just created.
Create table jun
(Id int not null primary key auto_increment, # sets the ID column to automatically grow.
Name nvarchar (30 ),
Passwd nvarchar (20); # create a table named jun and insert two columns, name and passwd.

Insert into jun
Values ('', 'user1', '123 ');
Insert into jun
Values ('', 'user2', '123 ');
Insert into jun
Values ('', 'user3', '123'); # insert three users.

You can use: show databases; # to check whether the database is correctly created.
: Show tables; # Check whether the table is created correctly.
: Select * from jun; # Check whether user insertion is correct.

5. Grant the virtual server to read only the jun table of the chen database.
Grant select on chen. jun to virtual @ localhost identified by '2013 ';
Verify that the operation just completed is successful:
Mysql-u virtual-p123 chen
Select * from jun; # You can see the username just inserted.

6. Create the pam Configuration File required by the virtual user. Vi/etc/pam. d/vsftpd. vu
Auth required pam_mysql.so user = virtual passwd = 123 host = localhost db = chen table = jun usercolumn = name passwdcolumn = passwd crypt = 0
Account required pam_mysql.so user = virtual passwd = 123 host = localhost db = chen table = jun usercolumn = name passwdcolumn = passwd crypt = 0

Pam_mysql.so # Is a program used for linux and mysql to access each other. The program copied from/usr/lib/security/pam_mysql.so to the/lib/security/directory above.
User = virtual # The user used to access Mysql.
Passwd = 123 # Corresponds to the user's password.
Host = localhost # indicates that mysql is on the local machine.
Db = chen # specifies the database on mysql.
Table = jun # specify to store the user's table on mysql.
Usercolumn = name # specifies the column of the user name.
Passwdcolumn = passwd # specifies the password column.
Crypt = 0
# Crypt = 0: plaintext Password
# Crypt = 1: Use the crpyt () function (corresponding to encrypt () in SQL data, encrypt () to randomly generate salt)
# Crypt = 2: Use the password () function in MYSQL for encryption.
# Crypt = 3: Indicates md5 hash.
Note: note that the preceding two statements are used. If one row is not written, you cannot press Enter! If there are multiple carriage return users, they cannot log on normally.

7. Configure the/etc/vsftpd. conf file.
Add:
Guest_enable = YES
Guest_username = virtual
Pam_service_name = vsftpd. vu
User_config_dir =/etc/vsftpd_user_conf

8. configure a separate configuration file for the user
Mkdir/etc/vsftpd_user_conf: Create the directory of the user's independent configuration file.
Mkdir user1 creates a file with the same name as the user and writes it to the file: local_root =/ftp/user1 to specify the user's logon directory.
Mkdir user2 user2 and user3 are the same as above
Mkdir user3

9. Create a user logon directory.
Mkdir-p/ftp/user1
Mkdir-p/ftp/user2
Mkdir-p/ftp/user3
Chown-R virtual. virtual/ftp

10. Create User virtual: useradd virtual
Chown virtual. virtual/home/virtual
Chmod 700/home/virtual

If no error occurs in the middle, the user in the table can log on to FTP.
Hope to help you!
Due to the busy time, please do not write anything wrong.

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.