1. 程式人生 > >005.FTP本地用戶訪問

005.FTP本地用戶訪問

mman all touch 允許 entos 查看當前目錄 sys binary eas

一 新建本地用戶

  1 [root@imxhy ftp]# useradd ftpuser	#用於登陸ftp的用戶
  2 [root@imxhy ftp]# passwd ftpuser
  3 Changing password for user ftpuser.
  4 New password:
  5 Retype new password:
  6 passwd: all authentication tokens updated successfully.

二 本地用戶配置項

2.1 基礎配置

  1 local_enable=YES			#允許本地用戶登陸
  2 write_enable=YES			#允許本地用戶上傳
  3
local_umask=022 #設置上傳的默認文件權限

2.2 安全選配

  1 chroot_local_user=YES			#開啟用戶目錄限制,把所有用戶都限制在用戶主目錄中
  2 chroot_list_enable=YES			#開啟允許訪問任何目錄的功能
  3 chroot_list_file=/etc/vsftpd/chrot_list	#允許訪問任何目錄的用戶依據文件保存位置

三 重啟ftp服務

  1 [root@imxhy ~]# service restart vsftpd		#Centos6系列
  2 [root@imxhy ~]# systemctl restart vsftpd	#Centos7系列

四 測試登陸

註意:本地用戶登陸後默認的主目錄為該用戶的家目錄:/home/【用戶名】

  1 E:\Temp>ftp 192.168.10.10
  2 連接到 192.168.10.10。
  3 220 (vsFTPd 3.0.2)
  4 用戶(192.168.10.10:(none)): ftpuser
  5 331 Please specify the password.
  6 密碼:
  7 230 Login successful.
  8 ftp> pwd
  9 257 "/home/ftpuser"

五 測試上傳及下載

5.1 上傳測試

  1 ftp> put ftpuser_upload.txt			#上傳至服務端
  2
200 PORT command successful. Consider using PASV. 3 150 Ok to send data. 4 226 Transfer complete.

5.2 下載測試

  1 [root@imxhy ftp]# cd /home/ftpuser/
  2 [root@imxhy ftpuser]# touch ftpuser_down.txt	#新建用於測試的文件
  3 ftp> get ftpuser_down.txt			#下載至本地
  4 200 PORT command successful. Consider using PASV.
  5 150 Opening BINARY mode data connection for ftpdown.txt (0 bytes).
  6 226 Transfer complete.

六 修改主目錄配置

註意:本地用戶登陸後默認的主目錄為該用戶的家目錄:/home/【用戶名】

6.1 添加配置項

  1 local_root=/tmp/ftpuser		#選配:設置所有本地用戶的FTP根目錄,但此配置無法區分不同用戶
  2 local_max_rate=0		#選配:限制最大傳輸速率(字節/秒)

6.2 查看修改後的目錄權限

  1 [root@imxhy ~]# ll -d /tmp/ftpuser
  2 drwxr-xr-x. 2 root root 6 Aug 28 19:39 /tmp/ftpuser/

6.3 新建ftp用戶組

  1 [root@imxhy ~]# groupadd ftpgroup		#創建ftp用戶組
  2 [root@imxhy ~]# gpasswd -a ftpuser ftpgroup	#將ftpuser添加到組

6.4 修改文件所屬組

  1 [root@imxhy ~]# chown root:ftpgroup /tmp/ftpuser/
  2 #將/tmp/ftpuser/目錄所屬組改為ftpgroup
  3 [root@imxhy ~]# chmod 775 /tmp/ftpuser/		#修改權限為775,使所屬組具備可讀寫執行權限
  4 [root@imxhy ~]# ls -ld /tmp/ftpuser/		#查看/tmp/ftpuser/目錄權限
  5 drwxrwxr-x. 2 root ftpgroup 21 Aug 28 19:42 /tmp/ftpuser/

註意:

1:強烈不建議將主目錄中其他人權限改為可讀寫且執行。

2:同時也不建議將/tmp/ftpuser主目錄所屬人改為ftpuser(會報錯)。

6.5 測試上傳及下載

  1 E:\Temp>ftp 192.168.10.10
  2 連接到 192.168.10.10。
  3 220 (vsFTPd 3.0.2)
  4 用戶(192.168.10.10:(none)): ftpuser
  5 331 Please specify the password.
  6 密碼:
  7 230 Login successful.
  8 ftp> pwd					#查看當前目錄(不再是默認目錄)
  9 257 "/tmp/ftpuser"
 10 ftp> get down.txt				#下載文件
 11 200 PORT command successful. Consider using PASV.
 12 150 Opening BINARY mode data connection for down.txt (0 bytes).
 13 226 Transfer complete.
 14 ftp> put upload.txt				#上傳文件
 15 200 PORT command successful. Consider using PASV.
 16 150 Ok to send data.
 17 226 Transfer complete.

七 總結

  • 1 默認上傳目錄建議為:/home/【用戶名】。
  • 2 如允許上傳,服務權限和系統目錄權限必須同時具備。
  • 3 本地用戶訪問傳輸的密碼為明文,存在安全隱患。
  • 4 本地用戶連接方式,無論是否采用默認的主目錄(/home/【用戶名】)還是自定義的主目錄(/tmp/ftpuser)
  • 都能通過cd切換到其他任意目錄,從而下載任意文件。因此chroot_local_user=YES必須限制。
  • 5 可將允許隨意切換目錄的用戶寫入/etc/vsftpd/chrot_list,從而針對特定用戶限制主目錄。

005.FTP本地用戶訪問