標籤:
一 需要的軟體包:
1. vsftpd:
2.MySQL
3.pam_mysql
4.pam-devel
5.openssl
6.tcp-wrappers
二 軟體安裝:
1.Openssl
使用yum -y install openssl
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 ‘[email protected]’
用root登陸mysql:
shell>mysql –u root –p
輸入密碼:
shell>Enter password:[email protected]
建立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
VSFTPD+MYSQL+PAM