Use a treasure trove to store the virtual user configuration records of vsftpd+mysql
Solution
1. Install vsftpd yum install vsftpd and it will be ok
2. The pam_mysql component is required, here
3. Take a look at the compilation parameters INSTALL. I used one parameter here, which is withmysql=/usr/local/amp/mysql5
4. Create a mysql database and table db=vsftpd table=users(username,userpass,homedir), and create a corresponding mysql account vsftpd vsftpd (of course you can also use root or an existing account)
5. Modify /etc/pam.d/vsftpd and add two lines auth required /usr/lib/security/pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=username passwdcolumn=userpass
account required /usr/lib/security/pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=username passwdcolumn=userpass
Copy code 6. Create a folder to store virtual user configuration files. Mine is in /etc/vsftpd/virtual, and there is a configuration file template called _tpl write_enable=YES
anon_mkdir_write_enable=YES
anon_upload_enable=YES
anon_other_write_enable=YES
Copying the code means that there is only one homedir missing
7. Open /etc/vsftpd/vsftpd.conf and change the settings to #Must have
listen=YES
#listen_port=10021
connect_from_port_20=YES
#Server Tips
ftpd_banner=Welcome to My FTP server.
#Close anonymous access
anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=YES
guest_enable=YES
#The account used by the virtual user. If this is root, then the owner of the file you upload is also root,
#Under normal security conditions, please set up a separate vsftpd user, just like the independent access user of mysql
guest_username=root
pasv_min_port=30000
pasv_max_port=30999
#This corresponds to the vsftpd under /etc/pam.d/. See Article 6
pam_service_name=vsftpd
#Virtual user configuration file directory
user_config_dir=/etc/vsftpd/virtual
xferlog_enable=YES
#xferlog_file=/var/log/vsftpd.log
xferlog_file=/data1/logs/vsftpd/vsftpd.log
anon_world_readable_only=NO
anon_umask=022
file_open_mode=0777
local_umask=022
#20080811 last modify
data_connection_timeout=120
Please note here when copying the code, the values of local_umask and anon_umask
The permission value of your file after uploading = 777 local_umask, that is, 022 in the above example. After you upload it, the file permission will be 755
8./etc/vsftpd/vsftpd restart
9. I still have two shells here, but my bash is very stupid, and there will be errors in the if judgment
Add ftp user #!/bin/bash
clear
echo "****************************"
echo "* Add vsftpd User Script *"
echo "* AnVy 2008.0516 *"
echo "******************************"
echo "Enter user account:[Enter Key]"
read username
echo "Username is $username, Now Enter the password:[Enter Key]"
read userpass
echo "Asign the user's ftp home directory:[Enter Key]"
read home
echo "create this dir?[y/n]:"
read $cd
if [ $cd="y" ]
then
mkdir $home
fi
#chown R www:www $home
/usr/local/amp/mysql5/bin/mysql uvsftpd pvsftpd
use vsftpd;
replace into users (username,userpass,homedir) values ('$username','$userpass','$home');
\q
EOF
cp /etc/vsftpd/virtual/_tpl /etc/vsftpd/virtual/$username
#Add home directory configuration parameters to the user configuration file
echo "local_root=$home" >> /etc/vsftpd/virtual/$username
echo "$username with homedir= $home was added."
Copy code ftp account list and delete user #!/bin/bash
clear
echo "******************************"
echo "* Add vsftpd User Script *"
echo "* AnVy 2008.0516 *"
echo "****************************"
echo "UserList:"
/usr/local/amp/mysql5/bin/mysql uvsftpd pvsftpd
use vsftpd;
select * from users;
\q
EOF
echo "Delete user account:[Enter Key]"
read username
/usr/local/amp/mysql5/bin/mysql uvsftpd pvsftpd
use vsftpd;
delete from users where username='$username';
\q
EOF
unlink /etc/vsftpd/virtual/$username
echo "$username without homedir was removed."
Copying the above settings of the code can easily implement my virtual user allocation. I don’t know much about the advanced settings
In this way, I can open a vsftpd account by entering my username, password, and home directory, and after the file is uploaded, the permissions are 755, which is fully usable.
[ ]
Attachment: Your user group cannot download or view attachments
D8888D’s reply content
\qPlease be sure to change it to half-width
D8888D’s reply content
Yes, when I configured it, I didn't add accounts automatically like this. I just configured it manually. This thing doesn't always change anyway.