1. 程式人生 > >【RHEL7】vsftpd服務程式的三種認證模式

【RHEL7】vsftpd服務程式的三種認證模式

我們使用vsftpd服務程式裡實現FTP協議,重點介紹三種認證模式的配置方法。也就是說,使用vsftpd配置伺服器,使用者可以通過以下三種方式訪問到FTP伺服器:

匿名開放模式:是一種最不安全的認證模式,任何人都可以無需密碼驗證而直接登入到FTP伺服器。

本地使用者模式:是通過Linux系統本地的賬戶密碼資訊進行認證的模式,相較於匿名開放模式更安全,而且配置起來也很簡單。但是如果被黑客破解了賬戶的資訊,就可以暢通無阻地登入FTP伺服器,從而完全控制整臺伺服器。

虛擬使用者模式:是這三種模式中最安全的一種認證模式,它需要為FTP服務單獨建立使用者資料庫檔案,虛擬出用來進行口令驗證的賬戶資訊,而這些賬戶資訊在伺服器系統中實際上是不存在的,僅供FTP服務程式進行認證使用。這樣,即使黑客破解了賬戶資訊也無法登入伺服器,從而有效降低了破壞範圍和影響。

 

準備:

1.伺服器安裝vsftpd軟體包

[[email protected] ~]# yum install -y ftp

2.清空iptables防火牆的預設策略

[[email protected] ~]# iptables -F
[[email protected] ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

3.確保客戶端可以ping通伺服器,以便之後測試。

 

4.客戶端安裝ftp客戶端工具,以便之後測試。

[[email protected] ~]# yum install -y ftp

 

 

匿名開放模式

 

服務端配置

1.去掉vsftpd服務主配置檔案中vsftpd.conf,不必要的註釋

[[email protected] ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak
[[email protected] ~]# grep -v "#" /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf

2.修改主配置

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf
#省略若干...
########
anonymous_enalbe=YES
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enalbe=YES
anon_other_write_enable=YES
########
#省略若干...

3.檢視並修改匿名模式下,訪問目錄 /var/ftp/ 的許可權

[[email protected] ~]# ls -ld /var/ftp/pub
drwxr-xr-x. 3 root root 16 Jul 13 14:38 /var/ftp/pub
[[email protected] ~]# chown -Rf ftp /var/ftp/pub
[[email protected] ~]# ls -ld /var/ftp/pub
drwxr-xr-x. 3 ftp root 16 Jul 13 14:38 /var/ftp/pub

 

4.檢視並關閉SELinux域對ftp的限制

[[email protected] ~]# getsebool -a | grep ftp

[[email protected] ~]# setsebool -P ftpd_full_access=on

 

5.重啟服務,並加入啟動項

[[email protected] ~]# systemctl restart vsftpd
[[email protected] ~]# systemctl enable vsftpd
 ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service

 

客戶端驗證

[[email protected] ~]# ftp 192.168.10.10
Connected to 192.168.10.10 (192.168.10.10).
220 (vsFTPd 3.0.2)
Name (192.168.10.10:root): anonymous
331 Please specify the password.
Password:此處敲擊回車即可
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> mkdir files
550 Create directory operation failed.

 

 

 

本地使用者模式

 

服務端配置

1.去掉vsftpd服務主配置檔案中vsftpd.conf,不必要的註釋。並修改vsftpd.conf檔案

[[email protected] ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak
[[email protected] ~]# grep -v "#" /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf
#省略若干...
########
anonymous_enable=NO
local_enable=YES
local_umask=022
write_enable=YES

userlist_enable=YES    #開啟userlist名單
userlist_deny=YES       #userlist名單中的使用者登入限制
########
#省略若干...

 

關於userlist名單,有興趣瞭解可以檢視我的另一篇:vsftpd --使用者名稱單檔案ftpusers和user_list

 

2.檢視並關閉SELinux域對ftp的限制

[[email protected] ~]# getsebool -a | grep ftp

[[email protected] ~]# setsebool -P ftpd_full_access=on

 

3.重啟服務,並加入啟動項

[[email protected] ~]# systemctl restart vsftpd
[[email protected] ~]# systemctl enable vsftpd
 ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service

 

客戶端驗證

[[email protected] ~]# ftp 192.168.10.10
Connected to 192.168.10.10 (192.168.10.10).
220 (vsFTPd 3.0.2)
Name (192.168.10.10:root): root
530 Permission denied.
Login failed.
ftp>

如果訪問受限,那就檢視一下 userlist 和  ftpusers檔案,確認有沒有對登入的使用者限制,一般都是這個,修改一下就好。

 

 

 

虛擬使用者模式

 

服務端配置

1 建立使用者資料庫檔案 vuser.db

[[email protected] ~]# cd /etc/vsftpd/
[[email protected] vsftpd]# vim vuser.list
zhangsan
redhat
lisi
redhat

[[email protected] vsftpd]# db_load -T -t hash -f vuser.list vuser.db
[[email protected] vsftpd]# file vuser.db
vuser.db: Berkeley DB (Hash, version 9, native byte-order)
[[email protected] vsftpd]# chmod 600 vuser.db
[[email protected] vsftpd]# rm -f vuser.list

 

2 建立ftp根目錄&虛擬使用者對映到本地的使用者

[[email protected] ~]# useradd -d /var/ftproot -s /sbin/nologin virtual
[[email protected] ~]# ls -ld /var/ftproot/
drwx------. 3 virtual virtual 74 Jul 14 17:50 /var/ftproot/
[[email protected] ~]# chmod -Rf 755 /var/ftproot/

 

3 建立用於虛擬使用者認證的 PAM配置檔案vsftpd.vu

[[email protected] ~]# vim /etc/pam.d/vsftpd.vu
auth       required     pam_userdb.so db=/etc/vsftpd/vuser
account    required     pam_userdb.so db=/etc/vsftpd/vuser


4 修改主配置檔案

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf

#省略若干...
########

anonymous_enalbe=NO
local_enabe=YES
guest_enable=YES
gusest_name=virtual
pam_service_name=vsftpd.vu
allow_writeable_chroot=YES

########
#省略若干...


5 為虛擬使用者設定許可權 建立目錄&寫配置檔案

[[email protected] ~]# mkdir /etc/vsftpd/vusers_dir/
[[email protected] ~]# cd /etc/vsftpd/vusers_dir/
[[email protected] vusers_dir]# touch lisi
[[email protected] vusers_dir]# vim zhangsan
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

 

6.修改主配置檔案 將許可權目錄新增到檔案中

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf
#省略......
user_config_dir=/etc/vsftpd/vusers_dir
#省略......

 

7.檢視並關閉SELinux域對ftp的限制

[[email protected] ~]# getsebool -a | grep ftp

[[email protected] ~]# setsebool -P ftpd_full_access=on

 

8.重啟服務,並加入啟動項

[[email protected] ~]# systemctl restart vsftpd
[[email protected] ~]# systemctl enable vsftpd
 ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service

 

客戶端驗證

此時,不但可以使用虛擬使用者模式成功登入到FTP伺服器,還可以分別使用賬戶zhangsan和lisi來檢驗他們的許可權。當然,讀者在生產環境中一定要根據真實需求來靈活配置引數,不要照搬這裡的實驗操作。

[[email protected] ~]# ftp 192.168.10.10
Connected to 192.168.10.10 (192.168.10.10).
220 (vsFTPd 3.0.2)
Name (192.168.10.10:root): lisi
331 Please specify the password.
Password:此處輸入虛擬使用者的密碼
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mkdir files
550 Permission denied.
ftp> exit
221 Goodbye.
[[email protected] ~]# ftp 192.168.10.10
Connected to 192.168.10.10 (192.168.10.10).
220 (vsFTPd 3.0.2)
Name (192.168.10.10:root): zhangsan
331 Please specify the password.
Password:此處輸入虛擬使用者的密碼
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mkdir files
257 "/files" created
ftp> rename files database
350 Ready for RNTO.
250 Rename successful.
ftp> rmdir database
250 Remove directory operation successful.
ftp> exit
221 Goodbye.

 

 

參考:https://www.linuxprobe.com/chapter-11.html