VSFTPD+MYSQL+PAM

一           須要的軟件包:

1. vsftpd:mysql

2.MySQL算法

3.pam_mysqlsql

4.pam-develshell

5.openssl數據庫

6.tcp-wrappersapp

二           軟件安裝:tcp

1.Opensslide

使用yum  -y install opensslui

2.MySQL加密

使用yum–y install mysql

3.pam_mysql

下載地址:http://colocrossing.dl.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz

使用./configure–with-openssl 使用支持MD5加密算法

若是是使用源代碼編譯的mysql,還須要加./configure--with-mysql=/usr/local/mysql的安裝路徑

這個軟件主要用途是使用pam模塊對Mysql進行認證。在配置Pam文件的時候須要用到pam_mysql.so。源碼編譯完默認安裝在/usr/lib/security/pam_mysql.so.由於在下面的pam文件中,我直接使用的pam_mysql.so文件,因此須要創建一個文件鏈接到/lib/security/中,使用ln –s /usr/lib/security/pam_mysql.so  /lib/security/pam_mysql.so。若是不創建這個文件的的鏈接到/lib/security/文件夾中,pam程序文件沒法找到須要使用的pam認證文件。若是沒有作這個文件鏈接,則在pam配置文件中就須要將pam_mysql.so改爲/usr/lib/security/pam_mysql.so 

4.pam-devel

使用yum–y install pam-devel進行安裝便可。

5. tcp_wrappers

使用yum–y install tcp-wrappers安裝tcp-wrappers

 

6.vsftpd

下載地址:https://security.appspot.com/downloads/vsftpd-3.0.2.tar.gz

源碼編譯前,須要更改一個文件,將安裝包中的builddefs.h打開,將其中的#undefVSF_BUILD_TCPWRAPPERS中的undef改爲#defineVSF_BUILD_TCPWRAPPERS,使支持tcp-wrapper

三           配置(咱們以用戶名爲user1密碼爲user1例)

1.mysql配置

啓動數據庫mysql

shell>service mysqld start

設置mysql的管理員密碼:

shell>mysqladmin -u root password ‘limg@4px.com’

用root登錄mysql:

shell>mysql –u root –p

輸入密碼:

shell>Enter password:limg@4px.com

建立ftp數據庫:

mysql>create database ftp;

受權用戶名爲ftp,密碼爲111111的用戶查詢ftp數據庫中的表:

mysql>grant select on ftp * to ‘ftp’@’localhost’identified by ‘111111’;

從新刷權限表到內存:

mysql>flush privilieges;

使用ftp數據庫:

mysql>use ftp;

建立名爲users的表:

mysql>create tables users(id int not null auto_incrementprimary key,name varchar(50) not null,passwd varchar(50) not null,unique(name))engine = myisam;

添加用爲名爲user1,密碼user1的用戶到表users中:

mysql>insert into user(name,passwd) value (‘user1’,md5(‘user1’));

退出數據庫:

mysql>exit;

2.pam配置

創建vsftpd的pam文件:

shell>touch /etc/pam.d/vsftpd

打開vsftpd的pam文件:

shell>vi /etc/pam.d/vsftpd

編輯vsftpd的pam文件,添加兩行認證信息:

auth required pam_mysql.so user=ftp passwd=111111host=localhost db=ftp table=users usercolumn=name passwdcolumn=passwd crypt=3

account required pam_mysql.so user=ftp passwd=111111host=localhost db=ftp table=users usercolumn=name passwdcolumn=passwd crypt=3

3.VSFTPD配置

vsftpd.conf編輯:

anonymous_enable=NO

local_enable=YES

write_enable=YES

local_umask=022

dirmessage_enable=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_file=/var/log/vsftpd.log

nopriv_user=vsftpd

ascii_download_enable=YES

chroot_local_user=YES

listen=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

guest_enable=YES

guest_username=vsftpd

local_root=/home/vsftpd/$USER

user_sub_token=$USER

virtual_use_local_privs=YES

user_config_dir=/etc/vsftpd_user_conf

force_local_data_ssl=NO

force_local_logins_ssl=NO

3.根據vsftpd.conf文件中設置所要作的相應配置

創建vsftpd用戶,使其屬於users組

shell>useradd –G users –s /bin/false –d /home/vsftpdvsftpd

創建$USER目錄:

shell>mkdir /home/vsftpd/user1

賦於user1文件夾具備vsftp用戶和users組權限:

shell>chown vsftpd.useers /home/vsftpd/user1

使user1文件夾只有vsftpd用戶可讀寫:

shell>chmod 700 /home/vsftpd/user1

創建user_config_dir目錄:指定每一個用戶的不一樣權限

shell>mkdir /etc/vsftpd_user_conf

創建user1用戶的權限配置文件:

shell>touch /etc/vsftpd_user_conf/user1

編輯配置文件:

dirlist_enable=YES
download_enable=YES
local_root=/home/users/user1
write_enable=YES

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息