XiZi's Blog
Ubuntu 配置 vsftp+mysql
1、安装vsftpd
sudo apt-get install vsftpd
2、安装pam的mysql验证模块"pam_mysql.so"
sudo apt-get install libpam-mysql
3、配置vsftpd的PAM验证文件
vim /etc/pam.d/vsftpd
Here is an example,注释掉原有的,添加最下面两行
# Standard behaviour for ftpd(8).
# 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-session
#@include common-auth
#auth required pam_shells.so
#红色部分请根据自己的实际情况修改
# 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-session
#@include common-auth
#auth required pam_shells.so
auth required pam_mysql.so user=yoursqluser passwd= host=localhost db=vsftpd table=user usercolumn=name passwdcolumn=passwd crypt=0 sqllog=1 logtable=log logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logtimecolumn=time verbose=1
account required pam_mysql.so user=yoursqluser passwd=p@ssw0rd host=localhost db=vsftpd table=user usercolumn=name passwdcolumn=passwd crypt=0 sqllog=1 logtable=log logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logtimecolumn=time verbose=1p@ssw0rd
account required pam_mysql.so user=yoursqluser passwd=p@ssw0rd host=localhost db=vsftpd table=user usercolumn=name passwdcolumn=passwd crypt=0 sqllog=1 logtable=log logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logtimecolumn=time verbose=1p@ssw0rd
#红色部分请根据自己的实际情况修改
4、修改vsftpd的配置文件
vim vim /etc/vsftpd.conf
Here is an example,开启了ipv6的监听。
#去掉了所有的注释行
# listen=YES 这里注释掉是因为此项与listen_ipv6只能选一项,开启ipv6后自动侦听ipv4
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
guest_enable=YES
guest_username=ftp
anon_world_readable_only=NO
virtual_use_local_privs=YES
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
# listen=YES 这里注释掉是因为此项与listen_ipv6只能选一项,开启ipv6后自动侦听ipv4
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
guest_enable=YES
guest_username=ftp
anon_world_readable_only=NO
virtual_use_local_privs=YES
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
5、确定你对ftp目录的写权限
sudo chown -R ftp\: /home/ftp/
6、最后重启vsftpd服务,看看服务器好没好用?
sudo /etc/init.d/vsftpd restart
好了,可以看看你的服务器是不是好了?
root@www:/home# ftp localhost
Connected to localhost.
220 (vsFTPd 2.0.7)
Name (localhost:ado): admin
331 Please specify the password.
Password: //这里输入密码但看不见
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 109 1001 76 May 07 02:07 2.txt
drwxr-xr-x 2 109 1001 4096 May 07 01:10 a directory
-rwxr-xr-x 1 109 1001 1482 May 07 02:07 bridge
drwxr-xr-x 3 109 1001 4096 May 07 02:07 icc32
-rwx------ 1 109 1001 78771302 May 07 02:08 l_fc_p_10.1.015.tar.gz
-rw-r--r-- 1 109 1001 323 May 07 01:36 ls.txt
226 Directory send OK.
ftp> mkdir test
257 "/test" created
ftp> rm test
250 Remove directory operation successful.
ftp>exit
root@www:/home#
Connected to localhost.
220 (vsFTPd 2.0.7)
Name (localhost:ado): admin
331 Please specify the password.
Password: //这里输入密码但看不见
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 109 1001 76 May 07 02:07 2.txt
drwxr-xr-x 2 109 1001 4096 May 07 01:10 a directory
-rwxr-xr-x 1 109 1001 1482 May 07 02:07 bridge
drwxr-xr-x 3 109 1001 4096 May 07 02:07 icc32
-rwx------ 1 109 1001 78771302 May 07 02:08 l_fc_p_10.1.015.tar.gz
-rw-r--r-- 1 109 1001 323 May 07 01:36 ls.txt
226 Directory send OK.
ftp> mkdir test
257 "/test" created
ftp> rm test
250 Remove directory operation successful.
ftp>exit
root@www:/home#
P.S.
mysql 数据库的建立
#创建管理vsftpd用户的数据库和表,并插入测试帐号
#mysql -u root -p123456
CREATE DATABASE ftp;
USE ftp;
CREATE TABLE user(name CHAR(20) BINARY,passwd CHAR(20) BINARY);
INSERT INTO user (name,passwd) VALUES ('test1','12345');
INSERT INTO user (name,passwd) VALUES ('test2','54321');
GRANT SELECT on ftp.user to ftp@localhost identified BY '123456';
flush PRIVILEGES;
quit
#mysql -u root -p123456
CREATE DATABASE ftp;
USE ftp;
CREATE TABLE user(name CHAR(20) BINARY,passwd CHAR(20) BINARY);
INSERT INTO user (name,passwd) VALUES ('test1','12345');
INSERT INTO user (name,passwd) VALUES ('test2','54321');
GRANT SELECT on ftp.user to ftp@localhost identified BY '123456';
flush PRIVILEGES;
quit
配置过程参考:菜鸟ubuntu8.04桌面版配置vsftp+mysql+pam 无法使用,Ubuntu 8.04 Desktop上的vsftp+mysql+pam_mysql