ftp服務的簡單應用

 FTP

FTP:File Transfer Protocol   文件傳輸協議   

ftp服務可以使主機間共享文件和傳輸數據,它屬於網絡協議組的應用層,工作於TCP/IP 協議的21號端口,它的優點是可以促進文件盒數據的共享,但是由於ftp服務是明文傳輸,可能導致密碼和數據的泄露。
 
常見的ftp服務器端程序:
        wu-ftpd: 華盛頓大學研發
vsftpd: very Secure ftp Daemon    安全性高
proftpd: 
pureftpd: 
Filezilla
windows的ftp服務器“
Serv-U
Filezilla(開源)
 
客戶端程序:
CLI:
ftp
lftp
GUI:
gftpd
FlashFXP
Cuteftp
Filezilla
 
vsftpd:   紅帽中的rpm包是vsftpd,主要着眼於安全性
/etc/vsftpd: 配置文件目錄(rpm)
/etc/init.d/vsftpd: 服務腳本
/usr/sbin/vsftpd: 主程序
基於PAM實現用戶認證
/etc/pam.d/*          
/lib/security/*       認證模塊
/lib64/security/*      64位系統,認證模塊在這兒
支持虛擬用戶
vsftpd: /var/ftp: 提供服務的根目錄,這個目錄對於vsftpd這個進程來說,是不能有寫權限的,不允許除了root用戶以外,其它用戶有寫權限 文件目錄,其它用戶不能有寫權限,這是一種安全保證  
 
ftp: 用戶
匿名用戶 --> 有一個與之對應的系統用戶
系統用戶
虛擬用戶 --> 有一個與之對應的系統用戶
以上三種用戶,都要映射爲系統用戶
/var/ftp: ftp用戶的家目錄
匿名用戶默認訪問的目錄    因爲匿名用戶被映射爲ftp用戶
 
下面我們使用vsftpd來構建一個簡單的ftp服務器
1、關閉selinux,setenforce 0,永久關閉請編輯配置文件/etc/selinux/config使SELINUX=permissive,然後再執行setenforce 0,執行getenforce可查看是否關閉
2、配置yum源
3、裝載開發組環境 yum groupinstall "Development Tools" "Development Libraries"
 
1、yum install vsftpd 
安裝後生成的部分文件介紹:

2、ftp服務的運行者

3、在windows命令行界面下,匿名登錄

4、vsftpd的配置文件部分選項介紹,及其部分配置圖解

  1. 配置文件/etc/vsftpd/vsftpd.conf中的部分選項介紹: 
  2. 想詳細瞭解選項問題:man vsftpd.conf 
  3. anonymous_enable=                            #是否開放匿名用戶 
  4. local_enable =                               #是否開放系統用戶 
  5. write_enable=                                #是否能上傳文件的(定義的是系統用戶) 
  6. listen=YES                                   #表示vsftpd是否工作爲獨立守護進程 
  7. anon_upload_enable=                          #是否允許匿名用戶上傳文件 
  8. anon_mkdir_write_enable=                     #是否允許創建目錄 
  9. dirmessage_enable=YES                        #當用戶進入一個目錄時,是否顯示歡迎信息的    
  10. xferlog_enable=YES                           #是否打開傳輸日誌 
  11. xferlog_file=/var/log/xferlog                #打開這項才能看日誌的  
  12.  
  13. xferlog_std_format=YES                       #日誌文件是否顯示爲標準格式  
  14. #chown_uploads=YES                           #當用戶上傳完文件後,是否把屬主改了 
  15. #chown_username=whoever                      #改爲誰 
  16.   
  17. chroot_list_enable=YES                       #是不是用一個文件將特定用戶鎖在它的家目錄下 
  18. chroot_list_file=/etc/vsftpd/chroot_list     #在哪創建一個用戶列表,所有在列表中的用戶都將鎖在
  19. 用戶家目錄下 
  20.   
  21. 加一行:chroot_local_user=YES                #表示所有用戶都被禁錮在家目錄下 

/etc/vsftpd/ftpusers #所有寫在這個文件中的用戶都禁止訪問ftp服務器

userlist_enable=YES #使用這個列表中的用戶來控制用戶登錄的

userlist_deny=YES #這個列表中的用戶拒絕登錄ftp服務器

userlist_deny=NO #僅允許這個列表中的用戶登錄ftp

 

  1. [root@mail ~]# echo "redhat" | passwd --stdin peter  
  2. Changing password for user peter. 
  3. passwd: all authentication tokens updated successfully. 
  4. [root@mail ~]# cp /etc/inittab /home/peter  #複製一個文件至peter的家目錄下
  5. [root@mail ~]# cd /etc/vsftpd 
  6. [root@mail vsftpd]# ftp 172.16.25.3 
  7. Connected to 172.16.25.3. 
  8. 220 (vsFTPd 2.0.5) 
  9. 530 Please login with USER and PASS. 
  10. 530 Please login with USER and PASS. 
  11. KERBEROS_V4 rejected as an authentication type 
  12. Name (172.16.25.3:root): peter 
  13. 331 Please specify the password. 
  14. Password: 
  15. 230 Login successful. 
  16. Remote system type is UNIX. 
  17. Using binary mode to transfer files. 
  18. ftp> ls 
  19. 227 Entering Passive Mode (172,16,25,3,55,140) 
  20. 150 Here comes the directory listing. 
  21. 226 Directory send OK. 
  22. ftp> ls 
  23. 227 Entering Passive Mode (172,16,25,3,116,15) 
  24. 150 Here comes the directory listing. 
  25. -rw-r--r--    1 0        0            1666 Apr 17 20:10 inittab 
  26. 226 Directory send OK. 
  27. ftp> pwd 
  28. 257 "/home/peter" 
  29. ftp> cd /etc  #用戶可以訪問其他目錄,沒有鎖定在其家目錄下
  30. 250 Directory successfully changed. 
  31. ftp> ls 
  32. 227 Entering Passive Mode (172,16,25,3,88,24) 
  33. 150 Here comes the directory listing. 
  34. -rw-r--r--    1 0        0            2518 May 11  2011 DIR_COLORS 
  35. -rw-r--r--    1 0        0            2420 May 11  2011 DIR_COLORS.xterm 
  36. -rw-r--r--    1 0        0           92794 May 29  2007 Muttrc 
  37. -rw-r--r--    1 0        0               0 May 29  2007 Muttrc.local 
  38. drwxr-xr-x    4 0        0            4096 Mar 29 13:34 NetworkManager 
  39. drwxr-xr-x    9 0        0            4096 Mar 29 13:46 X11 
  40. -rw-r--r--    1 0        0            2562 Jan 15  2008 a2ps-site.cfg 

 

# 文件服務權限:文件系統權限*文件共享權限

5、匿名用戶上傳文件

# cd /etc/vsftpd/




 

匿名用戶映射爲了ftp用戶,雖然ftp服務的進程的執行者是ftp用戶,但是/var/ftp和/var/ftp/pub目錄的屬主和屬組

都是root用戶,所以雖然開啓了允許匿名用戶上傳文件的選項,但其還沒讀寫的權限,我們創建一個目錄,給ftp用戶

讀寫執行權限

  1. [root@mail vsftpd]# ftp 172.16.25.3 
  2. Connected to 172.16.25.3. 
  3. 220 (vsFTPd 2.0.5) 
  4. 530 Please login with USER and PASS. 
  5. 530 Please login with USER and PASS. 
  6. KERBEROS_V4 rejected as an authentication type 
  7. Name (172.16.25.3:root): ftp 
  8. 331 Please specify the password. 
  9. Password: 
  10. 230 Login successful. 
  11. Remote system type is UNIX. 
  12. Using binary mode to transfer files. 
  13. ftp> ls 
  14. 227 Entering Passive Mode (172,16,25,3,161,139) 
  15. 150 Here comes the directory listing. 
  16. drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub 
  17. drwxrwxr-x    2 0        0            4096 Apr 17 20:33 upload 
  18. 226 Directory send OK. 
  19. ftp> cd upload 
  20. 250 Directory successfully changed. 
  21. ftp> lcd /etc 
  22. Local directory now /etc 
  23. ftp> put fstab 
  24. local: fstab remote: fstab 
  25. 227 Entering Passive Mode (172,16,25,3,131,221) 
  26. 150 Ok to send data. 
  27. 226 File receive OK. 
  28. 684 bytes sent in 0.043 seconds (15 Kbytes/s) 
  29. ftp> ls 
  30. 227 Entering Passive Mode (172,16,25,3,24,127) 
  31. 150 Here comes the directory listing. 
  32. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  33. 226 Directory send OK. 
  34. ftp>  
6、刪除和創建目錄

  1. [root@mail vsftpd]# service vsftpd restart 
  2. Shutting down vsftpd:                                      [  OK  ] 
  3. Starting vsftpd for vsftpd:                                [  OK  ] 
  4. [root@mail vsftpd]# ftp 172.16.25.3 
  5. Connected to 172.16.25.3. 
  6. 220 (vsFTPd 2.0.5) 
  7. 530 Please login with USER and PASS. 
  8. 530 Please login with USER and PASS. 
  9. KERBEROS_V4 rejected as an authentication type 
  10. Name (172.16.25.3:root): ftp 
  11. 331 Please specify the password
  12. Password
  13. 230 Login successful. 
  14. Remote system type is UNIX. 
  15. Using binary mode to transfer files. 
  16. ftp> ls 
  17. 227 Entering Passive Mode (172,16,25,3,253,29) 
  18. 150 Here comes the directory listing. 
  19. drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub 
  20. drwxrwxr-x    2 0        0            4096 Apr 17 20:37 upload 
  21. 226 Directory send OK. 
  22. ftp> cd upload 
  23. 250 Directory successfully changed. 
  24. ftp> ls 
  25. 227 Entering Passive Mode (172,16,25,3,239,197) 
  26. 150 Here comes the directory listing. 
  27. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  28. 226 Directory send OK. 
  29. ftp> mkdir lsq  #成功創建目錄
  30. 257 "/upload/lsq" created 
  31. ftp> ls 
  32. 227 Entering Passive Mode (172,16,25,3,187,136) 
  33. 150 Here comes the directory listing. 
  34. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  35. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  36. 226 Directory send OK. 
  37. ftp> delete lsq 
  38. 550 Delete operation failed. 
  39. ftp> ls 
  40. 227 Entering Passive Mode (172,16,25,3,164,33) 
  41. 150 Here comes the directory listing. 
  42. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  43. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  44. 226 Directory send OK. 
  45. ftp> delete fstab  #成功刪除目錄
  46. 250 Delete operation successful. 
  47. ftp> ls 
  48. 227 Entering Passive Mode (172,16,25,3,39,238) 
  49. 150 Here comes the directory listing. 
  50. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  51. 226 Directory send OK. 
  52. ftp>  

7、怎樣鎖定用戶在其家目錄下

以上就是ftp服務,部分可以啓用的選項的應用,大家可以動手做做,瞭解一下其它選項的作用,這裏就不一一介紹了!
下一篇配置vsftpd+pam+mysql

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章