虛擬用戶的特點是只能訪問服務器為其提供的FTP服務,不能訪問系統的其它資源,所以,如果想讓用戶對FTP服務器站內具有寫權限,但又不允許訪問系統其他資源,可以使用虛擬用戶來提高系統的安全性。
在vsftpd中,誰這些虛擬用戶使用的是單獨的口令庫文件(pam_userdb),由可插入認證模塊(PAM)認證。使用這種方式更加安全,並且配置更加靈活。
安裝vsftpd,Berkeley Database(db4)
yum install vsftpd db4-utils db4 -y
創建虛擬用戶數據庫
vim /home/virtual_users.txt
senthil
centos
執行下面命令創建數據庫
db_load -T -t hash -f /home/virtual_users.txt /etc/vsftpd/virtual_users.db
創建PAM文件
vim /etc/pam.d/vsftpd_virtual
#%PAM-1.0
auth required pam_userdb.so db=/etc/vsftpd/virtual_users
account required pam_userdb.so db=/etc/vsftpd/virtual_users
session required pam_loginuid.so
vsftpd配置文件
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
listen=YES
listen_ipv6=NO
pam_service_name=vsftpd_virtual
userlist_enable=YES
tcp_wrappers=YES
guest_enable=YES
#啟用虛擬用戶
virtual_use_local_privs=YES
user_sub_token=$USER
local_root=/ftp/virtual/$USER
hide_ids=YES
allow_writeable_chroot=YES
#避免客戶端500錯誤
為虛擬用戶創建家目錄
mkdir -p /ftp/virtual/senthil
chown -R ftp:ftp /ftp/virtual/senthil/
啟動服務
systemctl start vsftpd
測試
C:\Users\Administrator>ftp 192.168.2.72
連接到 192.168.2.72。
220 (vsFTPd 3.0.2)
用戶(192.168.2.72:(none)): senthil
331 Please specify the password.
密碼:
230 Login successful.
ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 ftp ftp 670293 Feb 04 03:09 abc
-rw-r--r-- 1 ftp ftp 670293 Feb 04 03:08 services
226 Directory send OK.
ftp: 收到 127 字節,用時 0.00秒 127.00千字節/秒。
ftp> get services
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for services (670293 bytes).
226 Transfer complete.
ftp: 收到 670293 字節,用時 0.02秒 35278.58千字節/秒。
ftp>
參考資料:https://www.unixmen.com/install-vsftp-with-virtual-users-on-centos-rhel-scientific-linux-6-4/