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 ~]#

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
