vsftpd安裝很是簡單 :yum -y install vsftpd
需求:虛擬三個用戶,使用同一個家目錄。權限以下。
ftpadmin 讀寫刪除
ftpuser 讀寫
ftp 讀(下載)
1、建立虛擬用戶數據庫:
一、建立文件文件loginuser.txt 格式以下:
user_id
password
/home/loginuser.txt
ftpadmin
123456
ftpuser
123456
ftp
123456
二、生成數據庫文件:(安裝db4 和db4-utils包)
db_load -T -t hash -f /home/loginuser.txt /etc/vsftpd/vsftpd_login.db
chmod 600 /etc/vsftpd/vsftpd_login.db
bug:更改用戶時(或不用某個用戶),刪除vsftpd_login.db文件,而後從新執行上面命令。
三、配置pam文件
# vi /etc/pam.d/vsftpd.vu
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
進入目錄/etc/pam.d,新建空文件vsftpd.vu,內容爲:
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
注意:32位的系統中pam_userdb.so的目錄應爲/lib/security/pam_userdb.so
2、爲虛擬用戶建立本地系統用戶
useradd opendoc -d /data -s /bin/false
chown opendoc.opendoc /data
3、vsftpd.conf配置
anonymous_enable=NO
local_enable=YES
#write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_port=21
use_localtime=YES
userlist_enable=YES
chroot_local_user=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=opendoc
file_open_mode=0777
pam_service_name=vsftpd.vu
user_config_dir=/etc/vsftpd/vsftpd_user_conf
virtual_use_local_privs=YES
pasv_min_port=50000
pasv_max_port=60000
pasv_enable=yes
max_clients=200
max_per_ip=4
idle_session_timeout=600
ftpd_banner=Welcome to opendoc FTP service.
mkdir /etc/vsftpd/vsftpd_user_conf
# vi /etc/vsftpd/vsftpd_user_conf/ftpadmin 全部權限
write_enable=YES
anonymous_enable=NO
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
download_enable=Yes
local_root=/data
# vi /etc/vsftpd/vsftpd_user_conf/ftpuser 上傳權限
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
download_enable=NO
local_root=/data
# vi /etc/vsftpd/vsftpd_user_conf/ftp 只能下載
write_enable=NO
anon_world_readable_only=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
local_umask=022
download_enable=yes
local_root=/data
# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
測試:
# ftp -n localhost
Connected to ifidc.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
220 Welcome to tfhudong FTP service
ftp> use ftpadmin
331 Please specify the password.
Password:
230 Login successful.
ftp> quit
221 Goodbye.
# ftp -n localhost
Connected to ifidc.
220 Welcome to tfhudong FTP service
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
ftp> use ftpuser
331 Please specify the password.
Password:
230 Login successful.
ftp> quit
221 Goodbye.