Home >Database >Mysql Tutorial >vsftpd+pam+mysql服务器的实现_MySQL
一、vsftpd服务器端的安装:
yum install vsftpd
查看安装后生成的哪些文件
[root@station113 ~]# rpm -ql vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd《==================认证文件
/etc/rc.d/init.d/vsftpd《=============服务脚本
/etc/vsftpd《=========================程序的配置文件
/etc/vsftpd/ftpusers《=========
/etc/vsftpd/user_list《==================控制用户访问的
/etc/vsftpd/vsftpd.conf《================主配置文件
/etc/vsftpd/vsftpd_conf_migrate.sh
/var/ftp《===============================服务器文件存放目录
/var/ftp/pub《===========================服务器上共享文件的存放位置
启动服务
[root@station113 ~]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]
查看启动装态
[root@station113 ~]# ps aux | grep vsftpd
root 5200 0.0 0.0 52524 788 ? Ss 22:55 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 5207 0.0 0.0 103252 836 pts/0 S+ 22:56 0:00 grep vsftpd
[root@station113 ~]# ss -tnl《======查看一下21号端口是否启用起来了
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 32 *:21 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0
二、服务器端配置
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES《====启用匿名用户
local_enable=YES《=========充许本地用户访问
write_enable=YES《=========是否允许上传文件
anon_upload_enable=YES《====匿名用启上传
anon_mkdir_write_enable=YES《=匿名用户创建目录
anon_other_write_enable=YES《==匿名用户有写权限
定义欢迎信息
banner_file=/path/to/some_banner_file
ftp_banner=some string
dirmessage_enable=yes
在某ftp可访问的目录下创建.messages文件
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
vsftp控制登录用户的机制:
/etc/vsftpd/ftpusers中的用户都不允许使用ftp服务, 这是在/etc/pam.d/vsftpd中定义;
user_list配置文件有两种用法:
黑名单:
userlist_enable=YES
userlist_deny=YES
白名单
userlist_enable=YES
userlist_deny=NO
写在下面的目录中的用户都不允许登陆
[root@station113 ~]# cd /etc/vsftpd/
[root@station113 vsftpd]# ls
chroot_list ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@station113 vsftpd]# cat ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
[root@station113 vsftpd]# echo opentow >> ftpusers
[root@station113 vsftpd]# cat frpusers
pam安装
root@www ~]# tar xf pam_mysql-0.7RC1.tar.gz
[root@www ~]# cd pam_mysql-0.7RC1
[root@www pam_mysql-0.7RC1]# ./configure --with-mysql=/usr/local/mysql --with-openssl
[root@www pam_mysql-0.7RC1]# make && make install
[root@www pam_mysql-0.7RC1]# ls -l /lib/security/
total 124
-rwxr-xr-x 1 root root 885 Mar 26 18:23 pam_mysql.la
-rwxr-xr-x 1 root root 119100 Mar 26 18:23 pam_mysql.so
[root@www pam_mysql-0.7RC1]# ln -sv /lib/security/pam_mysql.so /lib64/security/
`/lib64/security/pam_mysql.so' -> `/lib/security/pam_mysql.so'
安装mysql服务器端
[root@www ~]# yum install mysql-sercer mysql-sever mysql-devel pam-mysql
[root@www ~]service mysqld start
登陆mysql
[root@www ~]# mysql
mysql> CREATE DATABASE vsftpd;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON vsftpd.* TO 'vsftpd'@'172.16.%,%'IDENTIFIED BY 'vsftpd';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> /q
Bye
验证一下是否能够登陆
[root@www ~]# mysql -uvsftpd -h172.16.24.8 -pvsftpd
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 13
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| vsftpd |
+--------------------+
3 rows in set (0.03 sec)
mysql> CREATE TABLE users (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,name VARCHAR(50) NOT NULL, password CHAR(48) NOT NULL);
Query OK, 0 rows affected (0.01 sec)
mysql> DESC users;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| password | char(48) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
3 rows in set (0.04 sec)
mysql> INSERT INTO users (name,password) VALUES ('tom','toms'),('jerry','jerrys');《====创建两个用户tom 和jerry;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> /q
Bye
配置vsftpd
[root@www ~]# vim /etc/pam.d/vsftpd.mysql
auth required /lib/security/pam_mysql.so user=vsftpd passwd=vsftpd host=172.16.24.8 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
account required /lib/security/pam_mysql.so user=vsftpd passwd=vsftpd host=172.16.24.8 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
以上请写你自己的地址。
~
注意:由于mysql的安装方式不同,pam_mysql.so基于unix sock连接mysql服务器时可能会出问题,此时,建议授权一个可远程连接的mysql并访问vsftpd数据库的用户。
.修改vsftpd的配置文件,使其适应mysql认证
建立虚拟用户映射的系统用户及对应的目录
[root@www ~]# useradd -s /sbin/nologin -d /var/ftproot vuser
[root@www ~]# chmod go+rx /var/ftproot/
请确保/etc/vsftpd.conf中已经启用了以下选项
anonymous_enable=YES《========启动匿名用户
local_enable=YES
write_enable=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
chroot_local_user=YES
[root@www ~]# cd /etc/vsftpd
[root@www vsftpd]# vim vsftpd.conf
而后添加以下选项
guest_enable=YES
guest_username=vuser
并确保pam_service_name选项的值如下所示
pam_service_name=vsftpd.mysql
[root@www ~]# service vsftpd reload
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@www ~]#