vsftpd是一款運(yùn)行在Linux操作系統(tǒng)上的FTP服務(wù)程序,不僅完全開源而且免費(fèi),此外,還具有很高的安全性、傳輸速度,以及支持虛擬用戶驗(yàn)證等其他FTP服務(wù)程序不具備的特點(diǎn)。
vsftd作為更加安全的文件傳輸?shù)姆?wù)程序,允許用戶以三種認(rèn)證模式登錄到FTP服務(wù)器上。
- 匿名開放模式: 是一種最不安全的認(rèn)證模式,任何人都可以無需密碼驗(yàn)證而直接登錄到FTP服務(wù)器。
- 本地用戶模式:
是通過Linux系統(tǒng)的本地賬戶密碼信息進(jìn)行認(rèn)證,相較于匿名開放模式更安全。但是如果被×××破解了賬戶的信息,就可以暢通無阻登錄FTP服務(wù)器,從而完全控制整臺(tái)服務(wù)器。 - 虛擬用戶模式:
是這三種模式中最安全的一種認(rèn)證模式,它需要為FTP服務(wù)單獨(dú)建立用戶數(shù)據(jù)庫文件,虛擬出用來進(jìn)行口令驗(yàn)證的賬戶信息,而這些賬戶信息在服務(wù)器系統(tǒng)中實(shí)際上是不存在的,僅供FTP服務(wù)程序進(jìn)行認(rèn)證使用。
實(shí)驗(yàn)環(huán)境
FTP服務(wù)器配置完yum倉庫后,安裝vsftpd服務(wù)程序
匿名開放模式
vsftpd服務(wù)程序默認(rèn)開啟了匿名開放模式,需要開啟匿名用戶的上傳、下載權(quán)限,以及讓匿名用戶創(chuàng)建、刪除、更名文件的權(quán)限。真實(shí)環(huán)境不建議這樣配置。FTP服務(wù)器匿名用戶對(duì)應(yīng)的系統(tǒng)用戶是ftp。
anonymous_enable=YES / /允許匿名訪問
anon_upload_enable=YES //允許匿名用戶上傳文件
anon_mkdir_write_enable=YES //允許匿名用戶創(chuàng)建目錄
anon_other_write_enable=YES//允許匿名用戶修改或刪除目錄
anon_umask=022 //設(shè)置匿名用戶上傳數(shù)據(jù)的權(quán)限掩碼
service iptables stop setenforce
在客戶端執(zhí)行ftp命令連接到ftp服務(wù)器,默認(rèn)訪問FTP根目錄/var/ftp?;诎踩钥紤],F(xiàn)TP根目錄的權(quán)限不允許匿名用戶或其他用戶有寫入權(quán)限(否則訪問時(shí)會(huì)報(bào)500錯(cuò)誤)
/var/ftp目錄下默認(rèn)創(chuàng)建了一個(gè)子文件夾pub,可以在匿名訪問時(shí)供上傳文件使用,那就要確保匿名用戶ftp對(duì)該目錄擁有寫入權(quán)限。
[root@RedHat6 drwxr-xr-x.
客戶端測(cè)試:
yum install ftp -y
Connected to ). ) Name ( Please specify the password. Password: Login successful. Remote system type UNIX. Using binary mode to transfer files. ftp> ls ). 150 Here comes the directory listing. -rw-r--r-- 1 0 0 7 Mar 26 02:42 ftp.txt drwxr-xr-x 2 14 0 4096 Feb 12 2013 pub 226 Directory send OK. ftp> local: ftp.txt remote: ftp.txt 227 Entering Passive ). 150 Opening BINARY mode data connection ). 226 Transfer complete. 7 bytes received ) ftp> cd pub 250 Directory successfully changed. ftp> put 123.txt local: 123.txt remote: 123.txt 227 Entering Passive ). 150 Ok to send data. 226 Transfer complete. 7 bytes sent ) ftp> ls 227 Entering Passive ). 150 Here comes the directory listing. -rw------- 1 14 50 7 Mar 26 02:44 123.txt 226 Directory send OK. ftp> mkdir data 257 "/pub/data" created ftp> quit 221 Goodbye.
本地用戶模式
之前用的是匿名開放模式,現(xiàn)在關(guān)了,然后開啟本地用戶模式。創(chuàng)建一個(gè)本地用戶zhangsan進(jìn)行測(cè)試。
anonymous_enable=NO //禁止匿名訪問
local_enable=YES //允許本地用戶模式
write_enable=YES //設(shè)置可寫權(quán)限
local_umask=022 //設(shè)置本地用戶模式創(chuàng)建文件的umask值
在客戶端執(zhí)行ftp命令連接到ftp服務(wù)器,默認(rèn)訪問的是該用戶的家目錄,而且該目錄的默認(rèn)所有者、所屬組都是該用戶自己。
客戶端測(cè)試:
[root@RedHat6-1 ~]# ftp 192.168.10.50 Connected to 192.168.10.50 (192.168.10.50). 220 (vsFTPd 2.2.2) Name (192.168.10.50:root): zhangsan //zhangsan用戶登入 331 Please specify the password. Password: //輸入用戶的密碼 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. 257 "/files" created 227 Entering Passive Mode (192,168,10,50,117,63). 150 Here comes the directory listing. drwxr-xr-x 2 500 500 4096 Mar 26 03:03 files 226 Directory send OK. 350 Ready for RNTO. 250 Rename successful. 227 Entering Passive Mode (192,168,10,50,147,228). 150 Here comes the directory listing. drwxr-xr-x 2 500 500 4096 Mar 26 03:03 database 226 Directory send OK. 250 Remove directory operation successful. 227 Entering Passive Mode (192,168,10,50,123,117). 150 Here comes the directory listing. 226 Directory send OK. 221 Goodbye.
需要注意的是7版本需要在配置文件添加“allow_writeable_chroot=YES”參數(shù)才允許本地用戶登錄。 //允許對(duì)禁錮的FTP根目錄執(zhí)行寫入操作,而且不拒絕用戶的登錄請(qǐng)求
1.禁錮宿主目錄
若還希望將所有的宿主目錄禁錮在其宿主目錄中,可以添加chroot_local_user配置項(xiàng),否則用戶將能夠任意切換到服務(wù)器的/var/、/etc/、/boot/等宿主目錄以外的文件夾,這樣一來便存在安全隱患。
chroot_local_user=YES //禁錮宿主目錄
客戶端測(cè)試:
550 Failed to change directory. 550 Failed to change directory. 221 Goodbye.
2.黑白名單
然而當(dāng)使用root管理員登錄后,系統(tǒng)提示如下錯(cuò)誤信息:
Connected to ). ) Name (以root用戶登錄 Permission denied. Login failed.
這是因?yàn)関sftpd服務(wù)程序所在的目錄中默認(rèn)存放著一個(gè)名為“用戶名單”的文件user_list,默認(rèn)userlist_deny=YES,所以這個(gè)名單上出現(xiàn)的名字將不允許登陸到ftp服務(wù)器,也就是黑名單。
[root@RedHat6-2 ~]# cd /etc/vsftpd/ [root@RedHat6-2 vsftpd]# ls ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh [root@RedHat6-2 vsftpd]# vim user_list //查看user_list文件 # root bin daemon adm lp sync //這些用戶默認(rèn)不允許登錄ftp服務(wù)器 shutdown halt mail news uucp operator games nobody
虛擬用戶模式
第1步:
創(chuàng)建用于進(jìn)行FTP認(rèn)證的用戶數(shù)據(jù)庫文件,其中奇數(shù)行為賬戶名,偶數(shù)行為密碼。
[root@RedHat6 rose abc123 jack abc123
[root@RedHat6 vuser.db: Berkeley DB (Hash, version , native byte-order) [root@RedHat6 [root@RedHat6
第2步:
創(chuàng)建vsftpd服務(wù)程序用于存儲(chǔ)文件的根目錄以及虛擬用戶映射的系統(tǒng)本地用戶。FTP服務(wù)用語存儲(chǔ)文件的根目錄指的是,當(dāng)虛擬用戶登錄后訪問的默認(rèn)位置。
第3步:
建立用于支持虛擬用戶的PAM文件vfstpd.vu,其中“db=”參數(shù)是使用db_load命令生成的賬戶密碼數(shù)據(jù)庫文件的路徑。
auth required pam_userdb.so db=/etc/vsftpd/vuser account required pam_userdb.so db=/etc/vsftpd/vuser
第4步:
在vsftpd服務(wù)程序的主配置文件中通過pam_service_name參數(shù)將pam認(rèn)證文件的名稱修改為vsftpd.vu,再添加 guest_enable、guest_username參數(shù)。
anonymous_enable=NO //禁止匿名訪問
guest_enable=YES //開啟虛擬用戶模式
guest_username=virtual //指定虛擬用戶賬戶
pam_service_name=vsftpd.vu //指定PAM文件
第5步:
為虛擬用戶設(shè)置不同的權(quán)限。先創(chuàng)建虛擬用戶不同權(quán)限的配置文件的存放路徑,在這個(gè)路徑下再分別創(chuàng)建rose和jack命名的文件。
第6步:
再次修改vsftpd主配置文件,通過添加user_config_dir參數(shù)定義這兩個(gè)虛擬用戶不同權(quán)限的配置文件所存放的路徑,重啟vsftpd服務(wù)。
user_config_dir=/etc/vsftpd/vu_dir //單獨(dú)用戶配置文件
客戶端測(cè)試:
Connected to ). ) Name ( Please specify the password. Password: Login successful. Remote system type UNIX. Using binary mode to transfer files. ftp> put anaconda-ks.cfg local: anaconda-ks.cfg remote: anaconda-ks.cfg ). 150 Ok to send data. 226 Transfer complete. 1498 bytes sent ) ftp> quit 221 Goodbye.
[root@RedHat6 總用量 -rw-r--r--.
如何在Ubuntu 18.04 LTS上安裝帶有TLS的VsFTPD服務(wù)器 http://www.sfodin.cn/Linux/2018-10/154930.htm