iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >vsftpd基于pam_mysql如何做虚拟用户认证
  • 364
分享到

vsftpd基于pam_mysql如何做虚拟用户认证

2024-04-02 19:04:59 364人浏览 薄情痞子
摘要

这篇文章给大家介绍vsftpd基于pam_Mysql如何做虚拟用户认证,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。(1)下载epel源[root@Centos7-175 ~

这篇文章给大家介绍vsftpd基于pam_Mysql如何做虚拟用户认证,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

(1)下载epel源

[root@Centos7-175 ~]# wget -O /etc/yum.repos.d/epel.repo Http://mirrors.aliyun.com/repo/epel-7.repo  #下载阿里云的epel源
[root@CentOS7-175 ~]# yum repolist

(2)安装所需要的包

[root@CentOS7-175 ~]# yum -y groupinstall "Development Tools" "Server PlatfORM Development"
[root@CentOS7-175 ~]# yum -y install vsftpd pam-devel mariadb-server mariadb-devel openssl-devel
[root@CentOS7-175 ~]# systemctl start mariadb.service
[root@CentOS7-175 ~]# systemctl enable mariadb.service

(3)编译安装pam_mysql模块

   vsftpd通过pam_mysql进行用户验证,需要安装pam_mysql模块,但是默认系统yum源不提供,所以需要编译安装pam_mysql模块

[root@CentOS7-175 ~]# mkdir /home/tools/
[root@CentOS7-175 ~]# cd /home/tools/
[root@CentOS7-175 tools]# tar xf pam_mysql-0.7RC1.tar.gz
[root@CentOS7-175 tools]# cd pam_mysql-0.7RC1/
[root@CentOS7-175 pam_mysql-0.7RC1]# ./configure --with-mysql=/usr --with-openssl=/usr --with-pam=/usr --with-pam-mods-dir=/lib64/security
[root@CentOS7-175 pam_mysql-0.7RC1]# make && make install
[root@CentOS7-175 pam_mysql-0.7RC1]# ls /lib64/security/pam_mysql.so  #查询是否编译成功,ls是否有pam_mysql.so模块
/lib64/security/pam_mysql.so

(4)备份vsftpd.conf配置文件

[root@CentOS7-175 pam_mysql-0.7RC1]# systemctl stop vsftpd
[root@CentOS7-175 pam_mysql-0.7RC1]# cd /etc/vsftpd
[root@CentOS7-175 vsftpd]# cp vsftpd.conf{,.bak}
[root@CentOS7-175 vsftpd]# ls vsftpd.conf*
vsftpd.conf  vsftpd.conf.bak

(5)配置mysql

[root@CentOS7-175 vsftpd]# mysql -uroot -p  #登录mysql
Enter passWord: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE vsftpd;   #创建vsftpd库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use vsftpd;   #进入vsftpd库
Database changed
MariaDB [vsftpd]> CREATE TABLE users (                   #创建users表
    -> id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
    -> name char(30) NOT NULL,
    -> password char(48)binary NOT NULL);
Query OK, 0 rows affected (0.05 sec)
MariaDB [vsftpd]> desc users;   #查看users表
+----------+----------+------+-----+---------+----------------+
| Field    | Type     | Null | Key | Default | Extra          |
+----------+----------+------+-----+---------+----------------+
| id       | int(11)  | NO   | PRI | NULL    | auto_increment |
| name     | char(30) | NO   |     | NULL    |                |
| password | char(48) | NO   |     | NULL    |                |
+----------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
MariaDB [vsftpd]> INSERT INTO users(name,password) VALUES ('tom',password('zhucke'));   #在表中插入数据用户
Query OK, 1 row affected (0.00 sec)
MariaDB [vsftpd]> INSERT INTO users(name,password) VALUES ('jerry',password('zhucke.com'));
Query OK, 1 row affected (0.00 sec)
MariaDB [vsftpd]> SELECT * FROM users;
+----+-------+-------------------------------------------+
| id | name  | password                                  |
+----+-------+-------------------------------------------+
|  1 | tom   | *9BDB807A93B6C421BBFCAC5EF1AE0835396EEE38 |
|  2 | jerry | *3E27BE6A3667961ABCCFCA4832F06B151F81185A |
+----+-------+-------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [vsftpd]> GRANT select ON vsftpd.* TO vsftpd@localhost IDENTIFIED BY 'zhucke';  #授权vsftpd用户登录mysql
Query OK, 0 rows affected (0.04 sec)
MariaDB [vsftpd]> GRANT select ON vsftpd.* TO vsftpd@127.0.0.1 IDENTIFIED BY 'zhucke'; #授权vsftpd用户登录mysql
Query OK, 0 rows affected (0.00 sec)
MariaDB [vsftpd]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
MariaDB [vsftpd]> exit
Bye

(6)测试用vsftpd用户登录mysql

[root@CentOS7-175 vsftpd]# mysql -uvsftpd -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server
 
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| vsftpd             |
+--------------------+
3 rows in set (0.01 sec)
 
MariaDB [(none)]> use vsftpd;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
MariaDB [vsftpd]> SELECT * FROM users;
+----+-------+-------------------------------------------+
| id | name  | password                                  |
+----+-------+-------------------------------------------+
|  1 | tom   | *9BDB807A93B6C421BBFCAC5EF1AE0835396EEE38 |
|  2 | jerry | *3E27BE6A3667961ABCCFCA4832F06B151F81185A |
+----+-------+-------------------------------------------+
2 rows in set (0.01 sec)

(7)配置pam

[root@CentOS7-175 vsftpd]# cd /etc/pam.d/
[root@CentOS7-175 pam.d]# vim vsftpd.mysql
[root@CentOS7-175 pam.d]# cat vsftpd.mysql
auth required pam_mysql.so user=vsftpd passwd=zhucke host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
account required pam_mysql.so user=vsftpd passwd=zhucke host=localhost db=vsftpd tablee=users usercolumn=name passwdcolumn=password crypt=2
[root@CentOS7-175 pam.d]# useradd -s /sbin/nologin -d /ftproot vuser
[root@CentOS7-175 pam.d]# ls -ld /ftproot/
drwx------ 3 vuser vuser 74 Jun 11 11:30 /ftproot/
[root@CentOS7-175 pam.d]# chmod Go+rx /ftproot/
[root@CentOS7-175 pam.d]# ls -ld /ftproot/
drwxr-xr-x 3 vuser vuser 74 Jun 11 11:30 /ftproot/
[root@CentOS7-175 pam.d]# vim /etc/vsftpd/vsftpd.conf
[root@CentOS7-175 pam.d]# tail -7 /etc/vsftpd/vsftpd.conf
pam_service_name=vsftpd.mysql
local_enable=YES
write_enable=YES
local_umask=022
guest_enable=YES
guest_username=vuser  #指明虚拟用户映射到的系统用户
[root@CentOS7-175 pam.d]# chmod -w /ftproot/
[root@CentOS7-175 pam.d]# systemctl restart vsftpd
[root@CentOS7-175 pam.d]# mkdir /ftproot/{pub,upload}

(8)Client:192.168.5.171上分别用tom用户和jerry用户登录ftp服务器

[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): tom   #用tom用户登录 
331 Please specify the password.
Password:
230 Login successful.   #登录成功
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls   #查看ftp服务内的文件
227 Entering Passive Mode (192,168,5,175,58,188).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Jun 11 03:34 pub
drwxr-xr-x    2 0        0               6 Jun 11 03:34 upload
226 Directory send OK.
ftp> exit
221 Goodbye.
[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): jerry   #用jerry用户登录
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,5,175,189,114).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Jun 11 03:34 pub
drwxr-xr-x    2 0        0               6 Jun 11 03:34 upload
226 Directory send OK.

(9)设置文件可以上传

[root@CentOS7-175 pam.d]# chown vuser /ftproot/upload/  #修改此目录属主为vuser用户
[root@CentOS7-175 pam.d]# ls -ld /ftproot/upload/
drwxr-xr-x 2 vuser root 6 Jun 11 11:34 /ftproot/upload/
[root@CentOS7-175 pam.d]# vim /etc/vsftpd/vsftpd.conf   #编译vsftpd.conf文件
anon_upload_enable=YES   #将此行#号去掉,开启文件上传
[root@CentOS7-175 pam.d]# systemctl restart vsftpd

(10)测试文件上传

[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): tom  #用tom用户登录
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload  #进入upload目录
250 Directory successfully changed.
ftp> lcd /etc   #进入本地的/etc目录
Local directory now /etc
ftp> put fstab   #上传fstab文件
local: fstab remote: fstab
227 Entering Passive Mode (192,168,5,175,72,65).
150 Ok to send data.
226 Transfer complete.
648 bytes sent in 0.000229 secs (2829.69 Kbytes/sec)
ftp> ls  #查看是否有fstab文件
227 Entering Passive Mode (192,168,5,175,187,100).
150 Here comes the directory listing.
-rw-------    1 1001     1001          648 Jun 11 03:50 fstab   #上传成功
226 Directory send OK.
ftp> exit
221 Goodbye.
[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): jerry   #用jerry用户登录
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload  #进入upload目录
250 Directory successfully changed.
ftp> lcd /etc   #进入本地的/etc/目录
Local directory now /etc
ftp> put issue  #上传issue文件
local: issue remote: issue
227 Entering Passive Mode (192,168,5,175,95,111).
150 Ok to send data.
226 Transfer complete.
23 bytes sent in 0.000659 secs (34.90 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,5,175,177,97).
150 Here comes the directory listing.
-rw-------    1 1001     1001          648 Jun 11 03:50 fstab
-rw-------    1 1001     1001           23 Jun 11 03:52 issue  #上传issue文件成功
226 Directory send OK.

(11)配置用户拥有不同的权限,一个可以上传,一个不可以上传

[root@CentOS7-175 pam.d]# cd /etc/vsftpd
[root@CentOS7-175 vsftpd]# mkdir vusers.conf.d
[root@CentOS7-175 pam.d]# cd vusers.conf.d
[root@CentOS7-175 vusers.conf.d]# vim tom
anon_upload_enable=YES    #tom用户可以上传
[root@CentOS7-175 vusers.conf.d]# vim jerry
anon_upload_enable=NO  #jerry用户不上传
[root@CentOS7-175 vsftpd]# vim /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/vusers.conf.d
[root@CentOS7-175 vsftpd]# systemctl restart vsftpd.service

(12)验证tom用户和jerry用户

[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): tom
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,5,175,205,162).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Jun 11 03:34 pub
drwxr-xr-x    2 1001     0              30 Jun 11 03:52 upload
226 Directory send OK.
ftp> cd upload
250 Directory successfully changed.
ftp> lcd /etc
Local directory now /etc
ftp> put grub2.cfg
local: grub2.cfg remote: grub2.cfg
227 Entering Passive Mode (192,168,5,175,211,51).
150 Ok to send data.  #tom用户上传成功
226 Transfer complete.
4213 bytes sent in 0.0815 secs (51.69 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,5,175,111,189).
150 Here comes the directory listing.
-rw-------    1 1001     1001          648 Jun 11 03:50 fstab
-rw-------    1 1001     1001         4213 Jun 11 04:04 grub2.cfg
-rw-------    1 1001     1001           23 Jun 11 03:52 issue
226 Directory send OK.
[root@CentOS7-171 ~]# ftp 192.168.5.175
Connected to 192.168.5.175 (192.168.5.175).
220 (vsFTPd 3.0.2)
Name (192.168.5.175:root): jerry   
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,5,175,31,254).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Jun 11 03:34 pub
drwxr-xr-x    2 1001     0              62 Jun 11 04:06 upload
226 Directory send OK.
ftp> lcd /etc
Local directory now /etc
ftp> cd upload
250 Directory successfully changed.
ftp> put issue
local: issue remote: issue
227 Entering Passive Mode (192,168,5,175,87,198).
550 Permission denied. #jerry测试结果是不能上传

关于vsftpd基于pam_mysql如何做虚拟用户认证就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

您可能感兴趣的文档:

--结束END--

本文标题: vsftpd基于pam_mysql如何做虚拟用户认证

本文链接: https://www.lsjlt.com/news/61426.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • vsftpd基于pam_mysql如何做虚拟用户认证
    这篇文章给大家介绍vsftpd基于pam_mysql如何做虚拟用户认证,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。(1)下载epel源[root@CentOS7-175 ~...
    99+
    2024-04-02
  • 基于MySql验证的vsftpd虚拟用户
    目录1. Mysql安装1.2 建表建库建用户1.3 创建远程连接账户2. 安装FTP服务器2.1 安装vsftpd2.2 安装pam_mysql2.2 建立pam认证所需文件2.3...
    99+
    2024-04-02
  • MySQL中怎么利用pam_mysql模块实现vsftpd虚拟用户
    MySQL中怎么利用pam_mysql模块实现vsftpd虚拟用户,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。一、实验环境的...
    99+
    2024-04-02
  • 怎么建立基于虚拟用户的VSftpd服务
    这篇文章主要介绍“怎么建立基于虚拟用户的VSftpd服务”,在日常操作中,相信很多人在怎么建立基于虚拟用户的VSftpd服务问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么建立基于虚拟用户的VSftpd服务...
    99+
    2023-06-09
  • MySql如何实现新建并验证vsftpd虚拟用户
    这篇文章将为大家详细讲解有关MySql如何实现新建并验证vsftpd虚拟用户,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1. Mysql安装yum -y install m...
    99+
    2023-06-25
  • Vsftpd+Mysql+Pam如何配置虚拟用户
    这篇文章主要介绍Vsftpd+Mysql+Pam如何配置虚拟用户,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!  一、VSFTPD的安装  目前,VSFTPD的最新版本是1.2.0版...
    99+
    2024-04-02
  • 如何编辑CentOS vsftpd虚拟用户文件数据
    如何编辑CentOS vsftpd虚拟用户文件数据,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。先建立CentOS vsftpd虚拟用户名单文件:[root@K...
    99+
    2023-06-16
  • Linux下如何安装vsftpd以及配置FTP虚拟用户
    这篇文章主要为大家展示了“Linux下如何安装vsftpd以及配置FTP虚拟用户”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux下如何安装vsftpd以及配置FTP虚拟用户”这篇文章吧。...
    99+
    2023-06-16
  • springsecurity如何实现基于token的认证方式
    这篇文章主要为大家展示了“springsecurity如何实现基于token的认证方式”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“springsecurity如何实现基于token的认证方式”...
    99+
    2023-06-20
  • MySQL如何实现Apache用户认证
    这篇文章主要介绍MySQL如何实现Apache用户认证,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!apache要求DSO方式编译安装,假定apache安装在/usr/local/a...
    99+
    2024-04-02
  • Flask中基于Token的身份认证如何实现
    今天小编给大家分享一下Flask中基于Token的身份认证如何实现的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。Flask提...
    99+
    2023-07-05
  • 基于域名的虚拟主机如何配置
    基于域名的虚拟主机配置可以通过以下步骤完成:1. 获取一个域名:首先,您需要购买一个域名,例如example.com。您可以通过注册...
    99+
    2023-08-22
    虚拟主机
  • Django中auth模块用户认证如何使用
    本文小编为大家详细介绍“Django中auth模块用户认证如何使用”,内容详细,步骤清晰,细节处理妥当,希望这篇“Django中auth模块用户认证如何使用”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。auth模...
    99+
    2023-07-05
  • 虚拟空间ssl证书如何使用
    要在虚拟空间上使用 SSL 证书,您需要完成以下步骤:1. 获取 SSL 证书:您可以从可信的 SSL 证书颁发机构(CA)购买 S...
    99+
    2023-09-04
    ssl证书
  • 基于虚拟主机如何建立个人网站
    要建立一个基于虚拟主机的个人网站,可以按照以下步骤进行操作:1. 购买虚拟主机:在互联网上选择一家可靠的虚拟主机供应商,购买适合个人...
    99+
    2023-08-22
    虚拟主机
  • 如何在MariaDB中进行用户认证管理
    在MariaDB中,用户认证管理主要涉及以下几个方面: 创建用户:使用CREATE USER语句创建新用户。例如,创建一个用户名为...
    99+
    2024-04-02
  • Linux下如何安装Postfix邮件虚拟用户及虚拟域
    小编给大家分享一下Linux下如何安装Postfix邮件虚拟用户及虚拟域,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Postfix基于虚拟用户虚拟域的邮件架构上...
    99+
    2023-06-27
  • 如何配置LINUX系统apache基于IP,基于port和基于域名的三种虚拟主机
    这篇文章主要介绍“如何配置LINUX系统apache基于IP,基于port和基于域名的三种虚拟主机”,在日常操作中,相信很多人在如何配置LINUX系统apache基于IP,基于port和基于域名的三种虚拟主机问题上存在疑惑,小编查阅了各式资...
    99+
    2023-06-10
  • ubuntu虚拟机如何查看用户名
    ubuntu虚拟机查看用户名的方法:打开终端使用任意账号,如:cat /etc/passwd每行对应一个用户,各列分别为:username:password(masked):userId;groupId:comment:homeD...
    99+
    2024-04-02
  • 基于Vue如何封装一个虚拟列表组件
    今天小编给大家分享一下基于Vue如何封装一个虚拟列表组件的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。组件效果使用方法<...
    99+
    2023-07-05
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作