1、安裝ftp服務(wù)
檢查ftp服務(wù)是否已安裝
rpm -qa |grep vsftpd
安裝ftp服務(wù)
yum install vsftpd
2完疫、創(chuàng)建用戶登錄
安裝數(shù)據(jù)庫(kù)
yum install db4-utils
創(chuàng)建虛擬用戶泰鸡,并轉(zhuǎn)換為本地?cái)?shù)據(jù)庫(kù)文件
/etc/vsftpd/logins.txt
db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftpd/logins.db
保護(hù)數(shù)據(jù)庫(kù)
chmod 600 /etc/vsftpd/logins.db
修改配置债蓝,用本地?cái)?shù)據(jù)庫(kù)進(jìn)行驗(yàn)證壳鹤,在/etc/vsftpd/vsftpd.conf配置
pam_service_name=vsftpd
修改/etc/pam.d/vsftpd配置,把原有的內(nèi)容全部刪掉或者注釋掉饰迹,再寫上:
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/logins
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/logins
創(chuàng)建虛擬用戶及目錄
useradd -d /cache1/Test_Log virtual
若提示useradd: unable to open password file芳誓,修改權(quán)限保護(hù)余舶,修改辦法如下:
[root@203 etc]# lsattr /etc/passwd
----i-------- /etc/passwd
[root@203 etc]# lsattr /etc/shadow
----i-------- /etc/shadow
[root@203 etc]# lsattr /etc/gshadow
----i-------- /etc/gshadow
[root@203 etc]# lsattr /etc/group
----i-------- /etc/group
[root@203 etc]# chattr -i /etc/passwd
[root@203 etc]# chattr -i /etc/shadow
[root@203 etc]# chattr -i /etc/gshadow
[root@203 etc]# chattr -i /etc/group
把虛擬賬號(hào)映射到virtual用戶,在/etc/vsftpd/vsftpd.conf配置
guest_enable=yes
guest_username=virtual
3锹淌、安全及限速配置
取消匿名登錄功能
anonymous_enable=NO
設(shè)定使用者不得更改目錄
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
新增一個(gè)文件/etc/vsftpd/chroot_list匿值,文件內(nèi)容為用戶名
限速
在/etc/vsftpd/vsftpd.conf配置增加一行
user_config_dir=/etc/vsftpd/userconf
創(chuàng)建用戶配置目錄
mkdir /etc/vsftpd/userconf
在/etc/vsftpd/userconf下新增一個(gè)名為用戶登錄名的文件,加入如下配置赂摆,意味著該用戶最高速度為500Kb/s(VSFTP對(duì)于速度的限制范圍大概在80%到120%之間挟憔,也就是限制最高速度為100Kb/s,但實(shí)際的速度可能在80Kb/s到120Kb/s之間烟号。如果頻寬不足绊谭,數(shù)值會(huì)低于此限制)
local_max_rate=500000
重啟服務(wù)
service vsftpd restart
4、維護(hù)
增刪用戶密碼
vi /etc/vsftpd/logins.txt
db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftpd/logins.db
限速大小修改
/etc/vsftpd/userconf
vi user1
5汪拥、可能遇到錯(cuò)誤
最后測(cè)試時(shí)出現(xiàn)530 login incrrect 提示达传,無(wú)法登陸。
查看日志 tail -n 20 /var/log/secure? 有如下信息
Oct 21 14:19:40 www vsftpd: PAM unable to dlopen(/lib/security/pam_userdb.so)
Oct 21 14:19:40 www vsftpd: PAM [error: /lib/security/pam_userdb.so: wrong ELF class: ELFCLASS32]
Oct 21 14:19:40 www vsftpd: PAM adding faulty module: /lib/security/pam_userdb.so
Oct 21 14:19:40 www vsftpd: pam_unix(vsftpd:auth): check pass; user unknown
Oct 21 14:19:40 www vsftpd: pam_unix(vsftpd:auth): authentication failure; logname= uid=0 euid=0 tty=ftp ruser=kanecruise rhost=60.55.8.102
Oct 21 14:19:40 www vsftpd: pam_succeed_if(vsftpd:auth): error retrieving information about user kanecruise
很明顯是 /lib/security/pam_userdb.so這個(gè)載入失敗迫筑。
檢查本地機(jī)器
pam.i386? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0.99.6.2-6.el5_5.2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? installed
pam.x86_64? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0.99.6.2-6.el5_5.2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? installed
兩種都已經(jīng)安裝宪赶,到底是載入的哪個(gè),哪個(gè)載入失敗呢脯燃?
機(jī)器是64位的搂妻,猜想應(yīng)該是要載入pam.x86_64
cat /etc/pam.d/vsftpd
#%PAM-1.0
auth? ? sufficient? ? ? /lib/security/pam_userdb.so? ? db=/etc/vsftpd/virtusers
account sufficient? ? ? /lib/security/pam_userdb.so? ? db=/etc/vsftpd/virtusers
session? ? optional? ? pam_keyinit.so? ? force revoke
auth? ? ? required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth? ? ? required pam_shells.so
auth? ? ? include system-auth
account? ? include system-auth
session? ? include system-auth
session? ? required? ? pam_loginuid.so
就是這里 /lib/security/pam_userdb.so 文件載入失敗,這個(gè)文件存在問題曲伊。
[root@www kanecruise]# ls /lib
lib/? lib64/
根目錄存在此兩個(gè)問題叽讳,嘗試把lib改為 lib64并確認(rèn) /lib/security/pam_userdb.so 此文件存在。
auth? ? sufficient? ? ? /lib64/security/pam_userdb.so? ? db=/etc/vsftpd/virtusers
account sufficient? ? ? /lib64/security/pam_userdb.so? ? db=/etc/vsftpd/virtusers
保存重啟vsftpd服務(wù)坟募。
重新測(cè)試岛蚤,登陸成功了。
6懈糯、限制IP訪問網(wǎng)段
只允許網(wǎng)段訪問:在/etc/hosts.deny 配置:
vsftpd: ALL EXCEPT 183.250.161.14
限制某個(gè)網(wǎng)段訪問在/etc/hosts.deny配置:
vsftpd:183.250.161.14
7涤妒、上傳資源類型限制:
deny_file={*.mp3,*.mov,.private}