Get the App
SLTechnology News&Howtos  ›  Servers  › 

Add mysql certification to ftp

Shulou Source: shulou.com Published: 2022-06-02 09:02:43 09月15日 Update

1. Install vsftpd, here yum installation or source code installation;

2. Install mysql, skip it, you can view the previous document;

3. Install pam-mysql, dependent on pam-devel package;

[root@WebA-136 ~]#tar xf pam_mysql-0.7RC1.tar.gz

[root@WebA-136 ~]#yum install pam-devel

[root@WebA-136 ~]#./ configure --with-mysql=/usr/local/mysql --with-openssl

[root@WebA-136 ~]#make && make install

[root@WebA-136 ~]#less README

[root@WebA-136 ~]#vim /etc/pam.d/vsftpd.mysql

[root@WebA-136 ~]#cat /etc/pam.d/vsftpd.mysql

[root@WebA-136 ~]#auth required /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=192.168.146.136 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=3 md5=yes

[root@WebA-136 ~]#account required /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=192.168.146.136 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=3 md5=yes

reconfigure database

create database vsftp;

grant selcet on vsftp.* to vsftpd@192.168.146.136 identified by '123456';

create tables

create table users(

id smallint auto_increment not null,

name char(20) binary not null,

password char(48) binary not null,

primary key(id))

;

View table structure

desc users;

You also need to insert virtual users here

INSERT INTO users(name,password)VALUES('tom',md5(123456)),('jack',md5(123456));

4. Modify the vsftpd.conf configuration file for mysql authentication

First create user

useradd -s /sbin/nologin -d /var/ftp-test vsftp

chmod go+rx /var/ftp-test

Make sure the following options are turned on in vsftpd.conf

[root@WebA-136 ~]#vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES

local_enable=YES

write_enable=YES

anon_upload_enable=NO

anon_mkdir_write_enable=NO

chroot_local_user=YES

Add the following options

guest_enable=YES

guest_username=vsftpd#####All virtual users must map to a specified user.

listen=YES

pam_service_name=vsftpd.mysql

Note: Different access permission settings can be implemented according to different virtual users.

Added in vsftpd.conf

user_config_dir=/etc/vsftpd/test

Add a file with the same name as the virtual user to/etc/vsftpd/test directory

cd /etc/vsftpd/test

vim tom

anon_upload_enable=YES

anon_mkdir_write_enable=YES

vim jack

anon_upload_enable=NO

anon_mkdir_write_enable=NO

Tags: User different file configuration authentication data database document permission source code directory structure Zhongxin Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Apple MariaDB Shulou Tech Info