用戶黑白名單
一個Linux主機中會多個用戶,而我們希望有些用戶不能去訪問ftp。ftp服務器可以通過配置文件“/etc/vsftpd/user_list”來設置一個用戶列表,這個列表可以是黑名單,也可以是白名單,具體要根據配置文件的參數“userlist_deny”來確定
1、黑名單
1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的參數“userlist_enable”,確保這個參數是yes
[ro ot@localhost wj]# gedit /etc/vsftpd/vsftpd.conf // 匿名登錄
userlist_enable=YES |
2)打開配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句話”userlist_deny=yes“。這個參數是yes,表示要設置一個黑名單
[root@localhost wj]# lftp david:543092@192.168.0.113:8765 // 用戶 david 登錄,密碼是 543092 userlist_deny=YES |
3)編輯文件“/etc/vsftpd/user_list“,在末尾追加一句話要設置的用戶名即可
[root@localhost ~]#gedit /etc/vsftpd/user_list # vsftpd userlist # If userlist_deny=NO, only allow users in this file # If userlist_deny=YES (default), never allow users in this file, and # do not even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied. root bin daemon adm lp sync shutdown halt mail news uucp operator games nobody david
|
4)重啟服務,測試黑名單內的用戶是否可以訪問,上面列出的都是不可以訪問的用戶
[root@localhost wj]# service vsftpd restart // 重啟服務
關閉 vsftpd : [ 失敗 ] 為 vsftpd 啟動 vsftpd : [ 確定 ] [root@localhost wj]# lftp weijie:123456@192.168.0.113:8765 // 用戶 weijie 登錄,可以訪問
lftp weijie@192.168.0.113:~> ls -rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip lftp weijie@192.168.0.113:~> bye [root@localhost wj]# lftp 192.168.0.113:8765 // 匿名用戶也可以
lftp 192.168.0.113:~> ls drwxr-xr-x 2 0 0 4096 Aug 14 06:38 pub lftp 192.168.0.113:/> [root@localhost wj]# lftp david:543092@192.168.0.113:8765 // 用戶 david 在黑名單中,因此無法訪問, ls 命令會失敗
lftp david@192.168.0.113:~> ls [0] ls & `ls' at 0 [ 重新連接前延時 : 28] lftp david@192.168.0.113:~> |
2、白名單
1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的參數“userlist_enable”,確保這個參數是yes
[ro ot@localhost wj]# gedit /etc/vsftpd/vsftpd.conf // 匿名登錄
userlist_enable=YES |
2)打開配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句話”userlist_deny=NO“。這個參數是NO,表示要設置一個白名單
[root@localhost wj]# lftp david:543092@192.168.0.113:8765 // 用戶 david 登錄,密碼是 543092 userlist_deny=NO |
3)編輯文件“/etc/vsftpd/user_list“,在末尾追加一句話要設置的用戶名即可
[root@localhost ~]#gedit /etc/vsftpd/user_list # vsftpd userlist # If userlist_deny=NO, only allow users in this file # If userlist_deny=YES (default), never allow users in this file, and # do not even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied. root bin daemon adm lp sync shutdown halt mail news uucp operator games nobody david
|
4)重啟服務,測試黑名單內的用戶是否可以訪問,上面列出的都是不可以訪問的用戶
[root@localhost wj]# service vsftpd restart // 重啟服務
關閉 vsftpd : [ 失敗 ] 為 vsftpd 啟動 vsftpd : [ 確定 ] [root@localhost wj]# lftp david:543092@192.168.0.113:8765 // 用戶 david 登錄,可以訪問
lftp weijie@192.168.0.113:~> ls -rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip lftp weijie@192.168.0.113:~> bye [root@localhost wj]# lftp weijie:123456@192.168.0.113:8765 // 用戶 weijie 不在白名單中,因此無法訪問, ls 命令會失敗
lftp david@192.168.0.113:~> ls [0] ls & `ls' at 0 [ 重新連接前延時 : 28] lftp david@192.168.0.113:~> bye [root@localhost wj]# lftp 192.168.0.113:8765 // 匿名用戶也不行
lftp 192.168.0.113:~> ls [0] ls & `ls' at 0 [ 重新連接前延時 : 28] lftp 192.168.0.113:~> |
做了一個Linux學習的平台,目前出來一個雛形,各位可以參考使用
鏈接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密碼:n7bk
