Vsftpd使用MySQL验证实验

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vsftpd使用MySQL验证实验相关的知识,希望对你有一定的参考价值。

Vsftpd使用mysql验证实验笔记

实验环境

主机

IP

作用

mysql.xruan.com

192.168.0.11

用于存储vsftpd虚拟用户信息

vsftp.xruan.com

192.168.0.12

提供ftp服务

实验步骤:

1步:安装vsftpd并测试可用性(在vsftp.xruan.com,192.168.0.12上执行)

[[email protected] ~]# yum install -y vsftpd

[[email protected] ~]# yum install -y lftp

[[email protected] ~]# lftp 192.168.0.12

lftp 192.168.0.12:~>

2步:安装mysql-server并创建用户和表(在mysql.xruan.com,192.168.0.11上执行)

[[email protected] ~]# yum install -ymysql-server &> /dev/null

[[email protected] ~]# rpm -q mysql-server

mysql-server-5.1.71-1.el6.x86_64

启动MySQL服务

[[email protected] ~]# service mysqld start

Initializing MySQL database:  WARNING: The host ‘CentOS6lsrv01‘ could notbe looked up with resolveip.

This probably means that your libc libraries arenot 100 % compatible

with this binary MySQL version. The MySQLdaemon, mysqld, should work

normally with the exception that host nameresolving will not work.

This means that you should use IP addressesinstead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right placefor your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQLroot USER !

To do so, start the server, then issue thefollowing commands:

 

/usr/bin/mysqladmin -u root password‘new-password‘

/usr/bin/mysqladmin -u root -h CentOS6lsrv01password ‘new-password‘

 

Alternatively you can run:

/usr/bin/mysql_secure_installation

 

which will also give you the option of removingthe test

databases and anonymous user created bydefault.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe &

 

You can test the MySQL daemon withmysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the/usr/bin/mysqlbug script!

 

                                                             [ OK  ]

Starting mysqld:                                          [  OK  ]


运行/usr/bin/mysql_secure_installation按提示设置好mysqlroot用户密码,这里我设置为“xruan”。

创建数据库并授予用户权限

mysql> CREATE DATABASE vsftpd;

Query OK, 1 row affected (0.00 sec)

 

mysql> GRANT ALL ON vsftpd.* TO [email protected]‘%‘IDENTIFIED BY ‘passwd‘;

Query OK, 0 rows affected (0.00 sec)

mysql> use vsftpd

Database changed

创建表

mysql> create table users (

    ->id int AUTO_INCREMENT NOT NULL,

    ->name char(20) binary NOT NULL,

    ->password char(50) binary NOT NULL,

    ->primary key(id)

    ->);

Query OK, 0 rows affected (0.02 sec)

mysql> insert into users(name,password)values(‘xruan‘,password(‘xruan‘));插入1行用户信息

Query OK, 1 row affected (0.00 sec)

mysql> insert into users(name,password)values(‘redhat‘,password(‘redhat‘)); 插入1行用户信息

Query OK, 1 row affected (0.00 sec)

mysql> FLUSH PRIVILEGES;    刷新权限

Query OK, 0 rows affected (0.00 sec)

 

3步:配置vsftpd基于MySQL表的虚拟用户(在vsftp.xruan.com192.168.0.12上执行)

首先必须完成基于MySQL表的认证,需要通过pam_mysql模块实现,先安装pam_mysql

先安装epel

到官方网站下载epel源的rpm安装包

https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

[[email protected] ~]# rpm -ivh epel-release-latest-6.noarch.rpm

[[email protected] ~]# yum install -y pam_mysql&> /dev/null

[[email protected] pam.d]# rpm -q pam_mysql

pam_mysql-0.7-0.12.rc1.el6.x86_64

 

建立pam认证所需要的配置文件(/etc/pam.d/vsftpd.mysql

[[email protected] ~]# vi/etc/pam.d/vsftpd.mysql

auth required /lib64/security/pam_mysql.souser=vsftpd passwd=passwd host=192.168.0.11 db=vsftpd table=usersusercolumn=name passwdcolumn=password crypt=2

account required /lib64/security/pam_mysql.souser=vsftpd passwd=passwd host=192.168.0.11 db=vsftpd table=usersusercolumn=name passwdcolumn=password crypt=2

 

创建虚拟用户映射的系统用户

[[email protected] ~]# useradd -r -s/sbin/nologin vuser -d /var/ftproot

[[email protected] ~]# mkdir /var/ftproot

[[email protected] var]# chown vuser:vuserftproot

 

编辑vsftpd配置文件 /etc/vsftpd/vsftpd.conf 如下设置:

listen=YES

anonymous_enable=YES

local_enable=YES

write_enable=YES

anon_upload_enable=NO

anon_mkdir_write_enable=NO

chroot_local_user=YES

guest_enable=YES

guest_username=vuser

pam_service_name=vsftpd.mysql

user_config_dir=/etc/vsftpd/vusers_config

 

为每个用户单独提供配置文件

user_config_dir=/etc/vsftpd/vusers_config  #在主配置文件(/etc/vsftpd/vsftpd.conf)中添加这个选项

[[email protected] vsftpd]# mkdir/etc/vsftpd/vusers_config

[[email protected] vsftpd]# vivusers_config/xruan      #设置xruan用户有所有权限

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

[[email protected] vsftpd]# vivusers_config/redhat     #设置anyisalin用户只有upload权限

anon_upload_enable=yes

 

重启vsftpd服务

[[email protected] vsftpd]# service vsftpdrestart

Shutting down vsftpd:                                      [ OK  ]

Starting vsftpd for vsftpd:                                [  OK  ]

 

4步:测试

[[email protected] vsftpd]# lftp -u xruan192.168.0.12 使用xruan用户登录

Password:

lftp [email protected]:~> lcd /etc 

lcd ok, local cwd=/etc

lftp [email protected]:/> put fstab

1224 bytes transferred

lftp [email protected]:~> rm fstab

rm ok, `fstab‘ removed   可依删除文件

 

[[email protected] vsftpd]# lftp -u redhat192.168.0.12       使用redhat用户登录

Password:

lftp [email protected]:~> lcd /etc

lcd ok, local cwd=/etc lftp [email protected]:/>put selinux/config

457 bytes transferred

lftp [email protected]:/> rm config

rm: Access failed: 550 Permission denied.(config)     不能删除文件

到此,实验成功!!!!!


本文出自 “Linux学习天地” 博客,请务必保留此出处http://linuxprince.blog.51cto.com/373334/1975676

以上是关于Vsftpd使用MySQL验证实验的主要内容,如果未能解决你的问题,请参考以下文章

实现基于mysql验证的vsftpd虚拟用户

实验-----基于MYSQL验证的vsftpd虚拟用户

实现基于MYSQL验证的vsftpd虚拟用户功能

实现基于mysql验证的vsftpd虚拟用户 (centos6)

实验-----实现基于文件验证的vsftpd虚拟用户

VSftpd使用MySQL存储虚拟用户进行认证