創建ftp服務器,設置並驗證其控制參數
安裝vsftp
ftp服務的安裝
[root@localhost Server]# rpm -ivhvsftpd-2.0.5-28.el5.x86_64.rpm
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
主配置文件重要參數
anonymous_enable=YES匿名用戶可否訪問,爲NO時匿名用戶不可登陸
local_enable=YES 是否啓用本地用戶
write_enable=YES 是否啓用本地用戶
local_umask=022 本地用戶上傳的權限掩碼
添加條目:
listen_port=2121 端口號默認爲20 更改爲2121
chroot_local_user=YES是否將用戶禁錮在主目錄
userlist_enable=YES白名單可用
listen_port=2121 端口號2121
userlist_deny=NO 允許白名單用戶
write_enable=YES 用戶可寫
local_root=/data/ftproot鎖定本地用戶家目錄地址
Max_clients=20 限制併發的客戶端個數
max_per_ip=2 限制每個客戶機ip的併發連接數
local_max_rate=100000 本地用戶最大傳輸速度(字節/秒)
1. 驗證匿名用戶的上傳下載權限
在服務器/var/ftp/pub/(ftp公共文件目錄)目錄下創建兩個測試文件ceshi1,ceshi2
服務器開啓Vsftp
[root@localhost~]# servicevsftpd restart
[root@localhost ~]# chkconfigvsftpd on
進入客戶機匿名登錄(ftp,anonymous。密碼爲空)
[root@localhost~]# ftp 192.168.1.1
Connectedto 192.168.1.1.
Name(192.168.1.1:root): ftp
331Please specify the password.
Password:
230Login successful.
上述登錄成功,進入pub文件夾
ftp>cd pub
250Directory successfully changed.
ftp>ls
227Entering Passive Mode (192,168,1,1,170,104)
150Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Jun 13 12:23 ceshi1
-rw-r--r-- 1 0 0 0 Jun 13 12:23ceshi2
226 Directory send OK.
下載文件ceshi1
ftp>get ceshi1
226 File send OK.
查看下載的文件
ftp>!ls ------帶感嘆號表示查看外部環境
anaconda-ks.cfg ceshi1 Desktop install.log install.log.syslog
可以看到已將ftp服務器中的文件ceshi1下載到本地的/root下了
上傳install.Log到服務器
ftp>put install.log
local: install.log remote: install.log
227 Entering Passive Mode (192,168,1,1,119,36)
550 Permission denied. -------顯示沒有權限
說明匿名用戶登錄只可下載不可上傳
2.本地用戶登錄本地用戶的家目錄,可以上傳下載
在用戶yeyue的家目錄下新建文件test1.txt
使用服務器創建的用戶yeyue在客戶端登錄訪問ftp
登錄後查看位置可知道用戶yeyue登錄後在其家目錄下
ftp>pwd
257 "/home/yeyue"
下載用戶yeyeu家目錄的test1.txt
ftp>get test1.txt
local:test1.txt remote: test1.txt
檢查:
ftp> !ls
anaconda-ks.cfg Desktopinstall.log.syslog
ceshi1 install.log test1.txt
上傳install.log到服務器
ftp> put install.log
可在服務器上檢查/home/yeyue
[root@localhost pub]# ls /home/yeyue
install.log test1.txt
可看到客戶機通過用戶yeyue上傳進服務器的install.log
3.設置禁止匿名用戶登錄
在服務器將主配置文件中設置anonymous_enable=NO
重啓服務後進入客戶機測試
[root@localhost ~]# ftp 192.168.1.1
Connected to 192.168.1.1.
KERBEROS_V4 rejected as an authentication type
Name (192.168.1.1:root): ftp
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
可看到通過匿名用戶訪問不可訪問
4.修改FTP端口號爲2121
listen_port=2121 端口號默認爲20 更改爲2121
重啓服務後進入客戶端進行測試
[root@localhost ~]# ftp 192.168.1.1
ftp: connect: Connection refused
可看到通過默認端口不能進入
[root@localhost ~]# ftp 192.168.1.1 2121
Connected to 192.168.1.1.
……..
Name (192.168.1.1:root):
可得通過2121端口可進入
5.將本地用戶禁錮在自己的家目錄下
在主配置文件中添加chroot_local_user=YES
客戶端通過本地用戶訪問
[root@localhost ~]# ftp 192.168.1.1 2121
Name (192.168.1.1:root): yeyue
331 Please specify the password.
Password:
230 Login successful.
ftp>pwd
257 "/"
可看到由實驗2用戶yeyue登錄後鎖定的家目錄已更改爲 / 目錄,可得用戶已被鎖定
6.驗證黑/白名單的生效範圍
(黑:/etc/vsftpd/ftpusers白:/etc/vsftpd/user_list)
將yeyue加入黑名單配置文件,在客戶機登錄驗證
[root@localhost pub]# vim /etc/vsftpd/ftpusers
[root@localhost ~]# ftp 192.168.1.1 2121
Login failed
進入後可輸入密碼,但登錄失敗,說明黑名單生效
新建用戶up,down。將黑名單中的yeyue刪除,將yeyue,up加入白名單並在主配置文件中加入userlist_deny=NO(白名單中的用戶可允許登錄)
[root@localhost ~]# ftp 192.168.1.1 2121
Name (192.168.1.1:root): down
530 Permission denied.
Login failed.
Down登錄後不提示輸入密碼就已經不允許登錄
[root@localhost ~]# ftp 192.168.1.1 2121
Connected to 192.168.1.1.
Name (192.168.1.1:root): up
331 Please specify the password.
Password:
230 Login successful.
白名單中的用戶up與yeyue可登入
注:白名單與黑名單同時添加用戶時,拒絕生效
7.設置本地用戶登錄到/data/ftproot/,up有上傳下載的權限,down只有下載的權限(默認權限)
將用戶up與down加入白名單。
主配置文件修改
userlist_enable=YES ---白名單可用
listen_port=2121 端口號2121
chroot_local_user=YES 鎖定用戶在家目錄
userlist_deny=NO 允許白名單用戶
write_enable=YES 用戶可寫
local_root=/data/ftproot鎖定本地用戶家目錄地址
創建目錄並在目錄下新建測試文件1.txt2.txt且賦予用戶up讀寫權限
[root@localhost pub]# mkdir -p /data/ftproot
[root@localhost pub]# setfacl -m u:up:rwx /data/ftproot
進入客戶機驗證
[root@localhost ~]# ftp 192.168.1.1 2121
Connected to 192.168.1.1.
Name (192.168.1.1:root): up
331 Please specify the password.
Password:
230 Login successful.
ftp>pwd
257 "/"
ftp>ls
227 Entering Passive Mode (192,168,1,1,250,64)
150 Here comes the directory listing.
-rw-r--r-- 10 0 0 Jun 13 13:49 1.txt
226 Directory send OK.
上述結果可看到用戶被鎖定在家目錄爲/data/ftproot
測試下載上傳
ftp> get 1.txt
local: 1.txt remote: 1.txt
227 Entering Passive Mode (192,168,1,1,86,190)
150 Opening BINARY mode data connection for 1.txt (0bytes).
226 File send OK.
ftp> !ls
1.txt2.txt ceshi1 install.log test1.txt
anaconda-ks.cfg Desktopinstall.log.syslog
下載成功
ftp> put ceshi1
ftp>ls
227 Entering Passive Mode (192,168,1,1,173,82)
150 Here comes the directory listing.
-rw-r--r-- 10 0 0 Jun 13 13:49 1.txt
-rw-r--r-- 1 502 502 0 Jun 13 13:56 ceshi1
226 Directory send OK.
上傳成功,說明用戶up擁有對ftp的上傳下載權限
用戶down登錄
[root@localhost ~]# ftp 192.168.1.1 2121
KERBEROS_V4 rejected as an authentication type
Name (192.168.1.1:root): down
230 Login successful
下載
ftp> get 2.txt
ftp> !ls
1.txt anaconda-ks.cfg Desktop install.log.syslog
2.txt ceshi1 install.log test1.txt
上傳
ftp> put test1.txt
553 Could not create file.
ftp>ls
-rw-r--r-- 10 0 0 Jun 13 13:49 1.txt
-rw-r--r-- 10 0 0 Jun 13 13:58 2.txt
-rw-r--r-- 1502 502 0 Jun 13 13:56 ceshi1
可看到上傳test1.txt文件不成功,說明down用戶沒有上傳權限
8.設置除up,down之外所有用戶登錄包括匿名用戶不可登錄
白名單中添加up,down
主配置文件中設定
local_enable=NO 本地用戶不啓用
anonymous_enable=NO 匿名用戶不可登錄
9.設置最多二十個併發且每個ip地址最多兩個併發
在主配置文件中添加:
Max_clients=20
max_per_ip=2
主配置文件中添加:
local_max_rate=100000