1.在本地建一用户用于虚拟用户管理
mkdir -p /mnt/vsftpdvirtual
groupadd -g 20000 vsftpdvirtual
useradd -u 20000 -g 20000 vsftpdvirtual -d /mnt/vsftpdvirtual
chown -R vsftpdvirtual.vsftpdvirtual /mnt/vsftpdvirtual
2.创建数据库,数据表,及用户
mysql -uroot -p
mysql>create database vsftpdvirtual; --建库
mysql>use vsftpdvirtual; --打开数据库
mysql>create table users(name char(16) binary,passwd char(16) binary); --建表
mysql>insert into users (name,passwd) values ('win',password('123456')); --添加登录ftp的虚拟用户
--用户名为win,密码为123456
mysql>\q
mysql -uroot -p
mysql>grant select on vsftpdvirtual.users to vsftpdvirtual@localhost identified by '123456'; --授权vsftpvirtual用户
3.配置文件如下
listen=YES
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
idle_session_timeout=600
data_connection_timeout=120
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
guest_enable=YES
guest_username=vsftpdvirtual
4./etc/pam.d/vsftpd如下
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
# Note: vsftpd handles anonymous logins on its own. Do not enable
# pam_ftp.so.
# Standard blurb.
@include common-account
@include common-session
@include common-auth
auth required pam_shells.so
auth required /lib/security/pam_mysql.so user=vsftpdvirtual passwd=123456 host=localhost db=vsftpdvirtual table=users usercolumn=name passwdcolumn=passwd crypt=2
account required /lib/security/pam_mysql.so user=vsftpdvirtual passwd=123456 host=localhost db=vsftpdvirtual table=users usercolumn=name passwdcolumn=passwd crypt=2
5.测试
目前只有匿名用户可以登录;
sudo ftp localhost
Password:
Connected to localhost.localdomain.
220 (vsFTPd 2.0.4)
Name (localhost:richardliu): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
新建的虚拟用户没办法登录
==============================
虚拟用户:win
密码:123456
sudo ftp localhost
Connected to localhost.localdomain.
220 (vsFTPd 2.0.4)
Name (localhost:richardliu): win
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp>
查看日志文件auth.log还是解决不了,郁闷中
========================================
tail -f /var/log/auth.log
Apr 25 09:42:26 server sudo: richardliu : TTY=pts/0 ; PWD=/home/richardliu ; USER=root ; COMMAND=/usr/bin/ftp localhost
Apr 25 09:43:20 server sudo: richardliu : TTY=pts/0 ; PWD=/home/richardliu ; USER=root ; COMMAND=/usr/bin/ftp localhost
Apr 25 09:43:26 server vsftpd: (pam_unix) check pass; user unknown
Apr 25 09:43:27 server vsftpd: (pam_unix) authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=127.0.0.1