Vsftpd + mysql virtual user practices in Linux-Linux Enterprise Application-Linux server application information. For details, refer to the following section. Vsftpd + mysql virtual user practices In Debian Linux
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 ), so I decided to use a virtual user. because Mysql is installed on the machine, I wanted to put the virtual user data in mysql. 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 their information is stored in the database, therefore, we also need a local user who can read the database content and set its local directory:
Mysql> insert into user (name, passwd) values ('test1', password ('123 '));
Mysql> insert into user (name, passwd) values ('test2', password ('123 '));
Mysql> quit
Enable ftpguest to access ftpu and table user:
# Mysql-u root mysql-p mysql> grant select on ftpu. user to ftpguest @ localhost identified by '123 ';
Mysql> quit
Step 3: Because vsftpd is verified by PAM, we also need a mysql package verified by PAM, which is called libpam-mysql In Debian.
Apt-get install libpam-mysql
Enable PAM verification For vsftpd:
# Vi/etc/pam. d/vsftpd
Comment out the previous content and add the following content:
Auth required pam_mysql.so user = ftpguest passwd = 123456 host = localhost db = ftpu table = user usercolumn = name passwdcolumn = passwd crypt = 2
Account required pam_mysql.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 through the mysql password () secret!
Step 4: Modify the vsftpd. conf file
# Vi/etc/vsftpd. conf
Join:
Uest_enable = YES
Guest_username = ftpguest
# Indicates that ftpguest is a virtual user of vsftp.
Virtual_use_local_privs = YES
# The virtual user has the same permissions as the local user
Write_enable = YES
Anon_upload_enable = YES
Anon_other_write_enable = YES
# Allow virtual users to upload, modify, and delete files
Chroot_local_user = YES
# Virtual users can only access their own directories
Anonymous_enable = NO
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 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 virtual users, music and doc, to the database:
# Mkdir/etc/vsftpd_user_conf
# Cd/etc/vsftpd_user_conf
# Touch music
# Echo "local_root =/home/username/music"> music
# Touch doc
# Echo "local_root =/home/username/doc"> doc
# Mkdir/home/username/music
# Chown ftpguest. nogroup/home/username/music
# Chmod 600/home/username/music
# Chown ftpguest. nogroup/home/username/doc
# Chmod 600/home/username/doc
Add user_config_dir =/etc/vsftpd_user_conf to vsftpd. conf.
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