2009年10月16日 星期五

VSFTP Configuration - vsftpd 安裝設定

1. 安裝:
RPM Requierment: vsftpd-2.0.5-16.el5

]#yum install vsftpd

2 設定:

2.1 設定vsftpd.conf:
]# vi /etc/vsftpd/vsftpd.conf

###begin of file###

##使用stand alone 方式啟動vsftpd daemon
listen=YES

#不允許 anonymous login
anonymous_enable=NO

#允許local端使用者登入
local_enable=YES

#允許檔案修改寫入
write_enable=YES

#設定新增檔案權限umask (目錄755檔案644)
local_umask=022

#允許顯示操作目錄訊息
dirmessage_enable=YES

#確認使用20 port 傳輸資料
connect_from_port_20=YES

##log 相關設定
#允許同時使用 vsftpd log及 xferlog
dual_log_enable=YES
#log timestamp 使用系統時間
use_localtime=YES
#xferlog log設定, 僅記錄檔案傳輸訊息.
xferlog_std_format=YES
xferlog_enable=YES
xferlog_file=/var/log/xferlog
#記錄所有vsftp user動作log
log_ftp_protocol=YES
#log路徑
vsftpd_log_file=/var/log/vsftpd.log

##使用change root 將使用者鎖在家目錄中
chroot_local_user=YES

##啟動禁止login的帳戶清單
#法一
userlist_enable=YES
#啟動清單中名單禁止
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list
#法二
#使用系統pam認證, 設定禁止名單
pam_service_name=vsftpd

##啟動chroot功能
chroot_list_enable=YES
#若chroot enable, 此為允許列出上層目錄名單
#若chroot disable, 此為不允許列出上層目錄名單
chroot_list_file=/etc/vsftpd/chroot_list
####其選項, # mask 起來即可.

###end of file ####

2.2 設定pam的vsftpd檔:

]# vi /etc/pam.d/vsftpd

###begin of file##
#%PAM-1.0
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
###end of file###

3 啟動測試:

3.1 啟動vsftpd:

]# /etc/init.d/vsftpd start

確認是否有錯誤訊息.

3.2 建立帳號:

]# useradd username
建立使用者username, 預設家目錄為/home/username.
]# passwd username
設定username密碼.

3.3 登入測試:

]# ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): username
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

ok!

3.4 檢查vsftp log:

]# tail -f /var/log/vsftpd.log
Fri Oct 16 14:35:17 2009 [pid 1461] FTP response: Client "127.0.0.1", "530 Please login with USER and PASS."
Fri Oct 16 14:35:23 2009 [pid 1461] FTP command: Client "127.0.0.1", "USER username"
Fri Oct 16 14:35:23 2009 [pid 1461] [username] FTP response: Client "127.0.0.1", "331 Please specify the password."
Fri Oct 16 14:35:25 2009 [pid 1461] [username] FTP command: Client "127.0.0.1", "PASS "
Fri Oct 16 14:35:25 2009 [pid 1460] [username] OK LOGIN: Client "127.0.0.1"
Fri Oct 16 14:35:25 2009 [pid 1462] [username] FTP response: Client "127.0.0.1", "230 Login successful."

ok!