文件服务器-ftp

来源:互联网 发布:淘宝定金链接怎么做 编辑:程序博客网 时间:2024/05/06 04:18

一 ftp相关知识

什么是ftp

FTP 是File TransferProtocol(文件传输协议)的英文简称,而中文简称为“文传协议”。用于Internet上的控制文件的双向传输。同时,它也是一个应用程序(Application)。基于不同的操作系统有不同的FTP应用程序,而所有这些应用程序都遵守同一种协议以传输文件。在FTP的使用当中,用户经常遇到两个概念:"下载"(Download)和"上传"(Upload)。"下载"文件就是从远程主机拷贝文件至自己的计算机上;"上传"文件就是将文件从自己的计算机中拷贝至远程主机上。用Internet语言来说,用户可通过客户机程序向(从)远程主机上传(下载)文件。

 

实现该协议的软件

vsftp

vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开发源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。[1]

vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。

在开源操作系统中常用的FTPD套件主要还有ProFTPD、PureFTPd和wuftpd等

 

tftp

TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。端口号为69。

 

FTP通讯原理

 

主动传输模式:客户端向服务端发送请求,服务器端同客户建立连接,在20端口传输数据(需要客户端可以在互联网上可以看到IP地址)

被动传输模式:服务器随机开一个端口向客户读发送数据;使用较多,端口随机,不好使用防火墙控制

 

传输数据

字符传输方式和二进制传输方式。

文本:二者皆可,假如是非文本,只能使用二进制传输方式,使用文本传输方式文件会损害。

服务器:默认是二进制模式

 

二 ftp——匿名用户

2.1 ftp——匿名用户下载

[sql] view plain copy
  1. --第一步,安装vsftpd  
  2. [root@serv01 ~]# yum install vsftpd -y  
  3.         
  4.  --第二步,测试配置文件的参数——listen  
  5. [root@serv01 ~]# rpm -ql vsftpd  
  6. [root@serv01 ~]# cd /etc/vsftpd/  
  7. [root@serv01 vsftpd]# ll  
  8. [root@serv01 vsftpd]# mv vsftpd.confvsftpd.conf.bak  
  9. [root@serv01 vsftpd]# cp vsftpd.conf.bakvsftpd.conf  
  10. [root@serv01 vsftpd]# ll  
  11. #文件为空,启动失败  
  12. [root@serv01 vsftpd]# echo "" >vsftpd.conf  
  13.        [root@serv01 vsftpd]# /etc/init.d/vsftpdstart  
  14. Starting vsftpd for vsftpd: 500 OOPS: vsftpd:not configured for standalone, must be started from inetd  
  15.                                                           [FAILED]  
  16. [root@serv01 vsftpd]# vim vsftpd.conf  
  17. [root@serv01 vsftpd]# cat vsftpd.conf  
  18. listen=yes  
  19. [root@serv01 vsftpd]# /etc/init.d/vsftpdstart  
  20. Starting vsftpd for vsftpd:                                [  OK  ]  
  21.         
  22.  --第三步,Serv02安装ftp客户端  
  23.  #ftp客户端  
  24. [root@serv02 ~]# yum install ftp -y  
  25. #匿名用户  
  26.        [root@serv02 vsftpd]# ftp 192.168.1.11  
  27. Connected to 192.168.1.11 (192.168.1.11).  
  28. 220 (vsFTPd 2.2.2)  
  29. Name (192.168.1.11:root): ftp  
  30. 331 Please specify the password.  
  31. Password:  
  32. 230 Login successful.  
  33. Remote system type is UNIX.  
  34. Using binary mode to transfer files.  
  35. ftp>  
  36.  ftp> ?  
  37. Commands may be abbreviated.  Commands are:  
  38.    
  39. !             debug           mdir             sendport       site  
  40. $            dir          mget             put         size  
  41. account        disconnect    mkdir            pwd              status  
  42. append         exit        mls        quit        struct  
  43. ascii              form             mode            quote            system  
  44. bell        get         modtime             recv              sunique  
  45. binary           glob              mput             reget            tenex  
  46. bye        hash              newer           rstatus          tick  
  47. case              help              nmap            rhelp             trace  
  48. cd          idle        nlist              rename        type  
  49. cdup             image           ntrans           reset             user  
  50. chmod          lcd         open             restart          umask  
  51. close             ls            prompt         rmdir            verbose  
  52. cr           macdef         passive         runique         ?  
  53. delete           mdelete        proxy            send  
  54.    
  55. ftp> ls  
  56. 227 Entering Passive Mode(192,168,1,11,93,120).  
  57. 150 Here comes the directory listing.  
  58. drwxr-xr-x   2 0        0            4096 Aug 13 10:29 pub  
  59. 226 Directory send OK.  
  60. [root@serv02 ~]# cd /var/ftp/pub/  
  61. [root@serv02 pub]# cp/boot/initramfs-2.6.32-131.0.15.el6.x86_64.img .  
  62. ftp> cd pub  
  63. 250 Directory successfully changed.  
  64. ftp> ls  
  65. 227 Entering Passive Mode(192,168,1,11,149,33).  
  66. 150 Here comes the directory listing.  
  67. -rw-r--r--   1 0        0        12587318 Aug 13 10:29initramfs-2.6.32-131.0.15.el6.x86_64.img  
  68. 226 Directory send OK.  
  69. ftp> getinitramfs-2.6.32-131.0.15.el6.x86_64.img  
  70. local:initramfs-2.6.32-131.0.15.el6.x86_64.img remote: initramfs-2.6.32-131.0.15.el6.x86_64.img  
  71. 227 Entering Passive Mode(192,168,1,11,105,144).  
  72. 150 Opening BINARY mode data connection forinitramfs-2.6.32-131.0.15.el6.x86_64.img (12587318 bytes).  
  73. 226 Transfer complete.  
  74. 12587318 bytes received in 0.0368 secs(341693.86 Kbytes/sec)  
  75. ftp> exit  
  76. 221 Goodbye.  
  77. [root@serv02 vsftpd]# lsinitramfs-2.6.32-131.0.15.el6.x86_64.img  
  78. initramfs-2.6.32-131.0.15.el6.x86_64.img  

2.2 ftp——匿名用户上传

[sql] view plain copy
  1. [root@serv01 vsftpd]# man vsftpd.conf  
  2.    
  3. #!ls:显示本机的文件和目录  
  4. #ls:显示服务器的文件和目录  
  5. --第一步,编辑配置文件,加上anon_upload_enable参数  
  6. [root@serv01 vsftpd]# vim vsftpd.conf  
  7. [root@serv01 vsftpd]# cat vsftpd.conf  
  8. listen=yes  
  9. anon_upload_enable=yes  
  10. --第二步,重启服务  
  11. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  12. Shutting down vsftpd:                                      [  OK  ]  
  13. Starting vsftpd for vsftpd:                                [  OK  ]  
  14.    
  15. --第三步,Serv02做测试  
  16. [root@serv02 ~]# ftp 192.168.1.11  
  17. Connected to 192.168.1.11 (192.168.1.11).  
  18. 220 (vsFTPd 2.2.2)  
  19. Name (192.168.1.11:root): ftp  
  20. 331 Please specify the password.  
  21. Password:  
  22. 230 Login successful.  
  23. Remote system type is UNIX.  
  24. Using binary mode to transfer files.  
  25. ftp> !ls  
  26. aa01.txt anaconda-ks.cfg initramfs-2.6.32-131.0.15.el6.x86_64.img install.log  install.log.syslog  
  27. #上传文件,发生失败,权限拒绝  
  28. ftp> put aa01.txt  
  29. local: aa01.txt remote: aa01.txt  
  30. 227 Entering Passive Mode(192,168,1,11,152,86).  
  31. 550 Permission denied.  
  32.    
  33. --第四步,修改ftp文件夹的权限,发现重新登录失败,把权限还原后登录正常(这样是安全考虑)  
  34. [root@serv01 var]# pwd  
  35. /var  
  36. [root@serv01 var]# chmod 777 ftp  
  37.    
  38. [root@serv02 ~]# ftp 192.168.1.11  
  39. Connected to 192.168.1.11 (192.168.1.11).  
  40. 220 (vsFTPd 2.2.2)  
  41. Name (192.168.1.11:root): ftp  
  42. 331 Please specify the password.  
  43. Password:  
  44. 500 OOPS: vsftpd: refusing to run with writableanonymous root  
  45. Login failed.  
  46.    
  47. [root@serv01 var]# chmod 755 ftp/  
  48. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  49. Shutting down vsftpd:                                      [  OK  ]  
  50. Starting vsftpd for vsftpd:                                [  OK  ]  
  51.    
  52. [root@serv02 ~]# ftp 192.168.1.11  
  53. Connected to 192.168.1.11 (192.168.1.11).  
  54. 220 (vsFTPd 2.2.2)  
  55. Name (192.168.1.11:root): ftp  
  56. 331 Please specify the password.  
  57. Password:  
  58. 230 Login successful.  
  59. Remote system type is UNIX.  
  60. Using binary mode to transfer files.  
  61.    
  62. --第五步,我们这样解决,新建一个文件夹,然后修改文件夹的权限,上传文件时上传到新建的目录里  
  63. [root@serv01 ftp]# pwd  
  64. /var/ftp  
  65. [root@serv01 ftp]# mkdir upload  
  66. [root@serv01 ftp]# chmod 777 upload  
  67. [root@serv01 ftp]# ls -ld upload/  
  68. drwxrwxrwx. 2 root root 4096 Aug 13 18:48upload/  
  69.    
  70. --第六步,重新修改配置文件,加上write_enable参数,重启服务,然后重新测试,上传成功  
  71. [root@serv01 vsftpd]# vim vsftpd.conf  
  72. [root@serv01 vsftpd]# cat vsftpd.conf  
  73. listen=yes  
  74. write_enable=yes  
  75. anon_upload_enable=yes  
  76. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  77. Shutting down vsftpd:                                      [  OK  ]  
  78. Starting vsftpd for vsftpd:                                [  OK  ]  
  79.    
  80.    
  81. [root@serv02 ~]# ftp 192.168.1.11  
  82. Connected to 192.168.1.11 (192.168.1.11).  
  83. 220 (vsFTPd 2.2.2)  
  84. Name (192.168.1.11:root): ftp  
  85. 331 Please specify the password.  
  86. Password:  
  87. 230 Login successful.  
  88. Remote system type is UNIX.  
  89. Using binary mode to transfer files.  
  90. ftp> !ls  
  91. aa01.txt anaconda-ks.cfg  initramfs-2.6.32-131.0.15.el6.x86_64.img  install.log install.log.syslog  
  92. ftp> ls  
  93. 227 Entering Passive Mode(192,168,1,11,161,243).  
  94. 150 Here comes the directory listing.  
  95. drwxr-xr-x   2 0        0            4096 Aug 13 10:29 pub  
  96. drwxrwxrwx   2 0        0            4096 Aug 13 10:48 upload  
  97. 226 Directory send OK.  
  98. ftp> cd upload  
  99. 250 Directory successfully changed.  
  100. #上传成功  
  101. ftp> put aa01.txt  
  102. local: aa01.txt remote: aa01.txt  
  103. 227 Entering Passive Mode(192,168,1,11,214,139).  
  104. 150 Ok to send data.  
  105. 226 Transfer complete.  
  106. 6 bytes sent in 0.000119 secs (50.42Kbytes/sec)  

2.3 ftp——匿名用户共享目录在其他位置

[sql] view plain copy
  1. --第一步,创建共享目录  
  2. [root@serv01 vsftpd]# mkdir /share  
  3. [root@serv01 vsftpd]# ls -ld /share/  
  4. drwxr-xr-x. 2 root root 4096 Aug 13 19:09/share/  
  5. --第二步,编辑配置文件  
  6. [root@serv01 vsftpd]# vim vsftpd.conf  
  7. [root@serv01 vsftpd]# cat vsftpd.conf  
  8. listen=yes  
  9. write_enable=yes  
  10. anon_upload_enable=yes  
  11. anon_root=/share  
  12. --第三步,重启服务  
  13. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  14. Shutting down vsftpd:                                      [  OK  ]  
  15. Starting vsftpd for vsftpd:                                [  OK  ]  
  16.    
  17. --第四步,拷贝文件,测试  
  18.        [root@serv01 vsftpd]# cp /boot/initramfs-2.6.32-131.0.15.el6.x86_64.img/share/ -rvf  
  19. `/boot/initramfs-2.6.32-131.0.15.el6.x86_64.img'-> `/share/initramfs-2.6.32-131.0.15.el6.x86_64.img'  
  20.    
  21. [root@serv02 ~]# ftp 192.168.1.11  
  22. Connected to 192.168.1.11 (192.168.1.11).  
  23. 220 (vsFTPd 2.2.2)  
  24. Name (192.168.1.11:root): ftp  
  25. 331 Please specify the password.  
  26. Password:  
  27. 230 Login successful.  
  28. Remote system type is UNIX.  
  29. Using binary mode to transfer files.  
  30. ftp> ls  
  31. 227 Entering Passive Mode(192,168,1,11,78,233).  
  32. 150 Here comes the directory listing.  
  33. -rw-r--r--   1 0        0        12587318 Aug 13 11:11initramfs-2.6.32-131.0.15.el6.x86_64.img  
  34. 226 Directory send OK.  
  35. ftp> pwd  
  36. 257 "/"  
  37. ftp>  
  38. ftp> getinitramfs-2.6.32-131.0.15.el6.x86_64.img  
  39. local:initramfs-2.6.32-131.0.15.el6.x86_64.img remote: initramfs-2.6.32-131.0.15.el6.x86_64.img  
  40. 227 Entering Passive Mode(192,168,1,11,120,127).  
  41. 150 Opening BINARY mode data connection forinitramfs-2.6.32-131.0.15.el6.x86_64.img (12587318 bytes).  
  42. 226 Transfer complete.  
  43. 12587318 bytes received in 0.149 secs(84466.18 Kbytes/sec)  
  44. ftp> exit  
  45. 221 Goodbye.  
  46. [root@serv02 ~]# ls  
  47. aa01.txt anaconda-ks.cfg initramfs-2.6.32-131.0.15.el6.x86_64.img install.log  install.log.syslog  


2.4 ftp——匿名用户登录时显示提示信息

[sql] view plain copy
  1. --第一步,修改配置文件  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. ftpd_banner="Welcome to mysite!!!----justdb"  
  9. --第二步,重启服务  
  10. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  11. Shutting down vsftpd:                                      [  OK  ]  
  12. Starting vsftpd for vsftpd:                                [  OK  ]  
  13. --第三步,测试  
  14. [root@serv02 ~]# ftp 192.168.1.11  
  15. Connected to 192.168.1.11 (192.168.1.11).  
  16. 220 "Welcome to mysite!!!----justdb"  

2.5登录时显示一个文件作为提示信息

[sql] view plain copy
  1. --第一步,创建登录时显示调用的文件  
  2. [root@serv01 vsftpd]# pwd  
  3. /etc/vsftpd  
  4. [root@serv01 vsftpd]# vim my_banner  
  5. [root@serv01 vsftpd]# cat my_banner  
  6. ############  
  7.      #  
  8.      $  
  9.      @  
  10.      ^  
  11.     &  
  12. ############  
  13.    
  14. --第二步,修改配置文件  
  15. [root@serv01 vsftpd]# vim vsftpd.conf  
  16. [root@serv01 vsftpd]# cat vsftpd.conf  
  17. listen=yes  
  18. write_enable=yes  
  19. anon_upload_enable=yes  
  20. anon_root=/share  
  21. #ftpd_banner="Welcome to mysite!!!----justdb"  
  22. banner_file=/etc/vsftpd/my_banner  
  23. --第三步,重启服务  
  24. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  25. Shutting down vsftpd:                                      [  OK  ]  
  26. Starting vsftpd for vsftpd:                                [  OK  ]  
  27. --第四步,测试  
  28. [root@serv02 ~]# ftp 192.168.1.11  
  29. Connected to 192.168.1.11 (192.168.1.11).  
  30. 220-############  
  31. 220-    #  
  32. 220-    $  
  33. 220-    @  
  34. 220-    ^  
  35. 220-    &  
  36. 220-############  
  37. 220  
  38. Name (192.168.1.11:root):  


2.6 ftp——匿名用户提示文件夹作用

[sql] view plain copy
  1. --第一步,编辑vsftpd.conf文件  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. #ftpd_banner="Welcome to mysite!!!----justdb"  
  9. #banner_file=/etc/vsftpd/my_banner  
  10. dirmessage_enable=yes  
  11. --第二步,创建文件夹和相关的文件夹说明文件  
  12. [root@serv01 share]# pwd  
  13. /share  
  14. [root@serv01 share]# mkdir upload  
  15. [root@serv01 share]# mkdir download  
  16. [root@serv01 share]# man vsftpd.conf  
  17. [root@serv01 share]# cd upload  
  18. [root@serv01 upload]# pwd  
  19. /share/upload  
  20. [root@serv01 upload]# vim .message  
  21. [root@serv01 upload]# cd ../download/  
  22. [root@serv01 download]# pwd  
  23. /share/download  
  24. [root@serv01 download]# vim .message  
  25. [root@serv01 download]# cat .message  
  26. this is download dir  
  27. [root@serv01 download]# cat../upload/.message  
  28. this is upload dir  
  29. --第三步,重启服务  
  30. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  31. Shutting down vsftpd:                                      [  OK  ]  
  32. Starting vsftpd for vsftpd:                                [  OK  ]  
  33.    
  34. --第四步,测试  
  35. [root@serv02 ~]# ftp 192.168.1.11  
  36. Connected to 192.168.1.11 (192.168.1.11).  
  37. 220 (vsFTPd 2.2.2)  
  38. Name (192.168.1.11:root): ftp  
  39. 331 Please specify the password.  
  40. Password:  
  41. 230 Login successful.  
  42. Remote system type is UNIX.  
  43. Using binary mode to transfer files.  
  44. ftp> cd upload  
  45. 250-this is upload dir  
  46. 250 Directory successfully changed.  
  47. ftp> cd ../download  
  48. 250-this is download dir  
  49. 250 Directory successfully changed.  
  50. ftp>  


2.7 ftp——匿名用户在共享文件夹创建目录

[sql] view plain copy
  1. --第一步,先测试创建文件夹,发现失败  
  2. [root@serv02 ~]# ftp 192.168.1.11  
  3. Connected to 192.168.1.11 (192.168.1.11).  
  4. 220 (vsFTPd 2.2.2)  
  5. Name (192.168.1.11:root): ftp  
  6. 331 Please specify the password.  
  7. Password:  
  8. 230 Login successful.  
  9. Remote system type is UNIX.  
  10. Using binary mode to transfer files.  
  11. ftp> cd upload  
  12. 250-this is upload dir  
  13. 250 Directory successfully changed.  
  14. ftp> mkdir test  
  15. 550 Permission denied.  
  16. ftp>  
  17. --第二步,编辑文件,加入anon_mkdir_write_enable参数  
  18. [root@serv01 vsftpd]# vim vsftpd.conf  
  19. [root@serv01 vsftpd]# cat vsftpd.conf  
  20. listen=yes  
  21. write_enable=yes  
  22. anon_upload_enable=yes  
  23. anon_root=/share  
  24. #ftpd_banner="Welcome to mysite!!!----justdb"  
  25. #banner_file=/etc/vsftpd/my_banner  
  26. dirmessage_enable=yes  
  27. anon_mkdir_write_enable=yes  
  28. --第三步,重启服务  
  29. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  30. Shutting down vsftpd:                                      [  OK  ]  
  31. Starting vsftpd for vsftpd:                                [  OK  ]  
  32. --第四步,测试,发现失败(550 Create directoryoperation failed.  
  33. )  
  34.        [root@serv02 ~]# ftp 192.168.1.11  
  35. Connected to 192.168.1.11 (192.168.1.11).  
  36. 220 (vsFTPd 2.2.2)  
  37. Name (192.168.1.11:root): ftp  
  38. 331 Please specify the password.  
  39. Password:  
  40. 230 Login successful.  
  41. Remote system type is UNIX.  
  42. Using binary mode to transfer files.  
  43. ftp> cd upload  
  44. 250-this is upload dir  
  45. 250 Directory successfully changed.  
  46. ftp> mkdir test  
  47. 550 Create directory operation failed.  
  48. --第五步,修改文件夹权限,再次登录后创建成功  
  49. [root@serv01 download]# chmod 777 ../upload/  
  50. [root@serv01 download]# ls -ld ../upload/  
  51. drwxrwxrwx. 2 root root 4096 Aug 13 19:28../upload/  
  52. ftp> mkdir test  
  53. 257 "/upload/test" created  
  54. ftp>  


2.8 ftp——匿名用户可以删除目录

[sql] view plain copy
  1. --第一步,修改配置文件,加入anon_other_write_enable参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. #ftpd_banner="Welcome to mysite!!!----justdb"  
  9. #banner_file=/etc/vsftpd/my_banner  
  10. dirmessage_enable=yes  
  11. anon_mkdir_write_enable=yes  
  12. anon_other_write_enable=yes  
  13. --第二步,重启服务  
  14. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  15. Shutting down vsftpd:                                      [  OK  ]  
  16. Starting vsftpd for vsftpd:                                [  OK  ]  
  17.    
  18. --第三步,测试  
  19. [root@serv02 ~]# ftp 192.168.1.11  
  20. Connected to 192.168.1.11 (192.168.1.11).  
  21. 220 (vsFTPd 2.2.2)  
  22. Name (192.168.1.11:root): ftp  
  23. 331 Please specify the password.  
  24. Password:  
  25. 230 Login successful.  
  26. Remote system type is UNIX.  
  27. Using binary mode to transfer files.  
  28. ftp> cd upload  
  29. 250-this is upload dir  
  30. 250 Directory successfully changed.  
  31. ftp> rm test  
  32. 250 Remove directory operation successful.  
  33. ftp> mkdir test  
  34. 257 "/upload/test" created  
  35. ftp> rmdir test  
  36. 250 Remove directory operation successful.  
  37. ftp>  
  38. #删除文件(delete命令)  
  39. ftp> delete aa01.txt  
  40. 250 Delete operation successful.  

2.9 ftp——匿名用户限制下载速度

 

[sql] view plain copy
  1. --第一步,安装ftp客户端  
  2. [root@larrywen opt]# yum install lftp -y  
  3. --第二步,拷贝文件测试  
  4. [root@larrywen ~]# cp/opt/soft/begin/RevolutionOS操作系统革命.rmvb .  
  5. --第三步,上传文件,发现速度很快,如果用户量访问过多,对系统造成的压力很大  
  6.    
  7.    
  8.    
  9. [root@larrywen ~]# lftp 192.168.1.11  
  10. lftp 192.168.1.11:~> cd upload  
  11. cd ok, cwd=/upload  
  12. lftp 192.168.1.11:/upload> putRevolutionOS操作系统革命.rmvb  
  13. 288570185 bytes transferred in 3 seconds(103.65M/s)                                      
  14. lftp 192.168.1.11:/upload> exit  
  15. --第四步,编辑文件  
  16. [root@serv01 vsftpd]# vim vsftpd.conf  
  17. [root@serv01 vsftpd]# cat vsftpd.conf  
  18. listen=yes  
  19. write_enable=yes  
  20. anon_upload_enable=yes  
  21. anon_root=/share  
  22. #ftpd_banner="Welcome to mysite!!!----justdb"  
  23. #banner_file=/etc/vsftpd/my_banner  
  24. dirmessage_enable=yes  
  25. anon_mkdir_write_enable=yes  
  26. anon_other_write_enable=yes  
  27. #一般设定为120K左右  
  28. anon_max_rate=1024000  
  29. --第五步,重启服务  
  30. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  31. Shutting down vsftpd:                                      [  OK  ]  
  32. Starting vsftpd for vsftpd:                                [  OK  ]  
  33.    
  34. --第六步,再次上传,发现速度大约在1M左右  
  35. [root@larrywen ~]# lftp 192.168.1.11  
  36. lftp 192.168.1.11:~> cd upload  
  37. cd ok, cwd=/upload                  
  38. lftp 192.168.1.11:/upload> putRevolutionOS操作系统革命.rmvb  
  39. 288570185 bytes transferred in 283 seconds(995.1K/s)    

2.10 ftp——匿名用户限制人数

[sql] view plain copy
  1. --第一步,修改配置文件,加入max_clients参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. #ftpd_banner="Welcome to my site!!!----justdb"  
  9. #banner_file=/etc/vsftpd/my_banner  
  10. dirmessage_enable=yes  
  11. anon_mkdir_write_enable=yes  
  12. anon_other_write_enable=yes  
  13. anon_max_rate=1024000  
  14. max_clients=3  
  15.    
  16. --第二步,重启服务  
  17. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  18. Shutting down vsftpd:                                      [  OK  ]  
  19. Starting vsftpd for vsftpd:                                [  OK  ]  
  20.    
  21. --第三步,测试  
  22. #连续打开三个终端,使用ftp或者lftp分别建立ftp连接,到第四个的时候,发现出错,不能连接,配置文件生效(但是这样一个用户打开3个终端就独占了,其他用户不允许连接了)  
  23. [root@larrywen 0813]# ftp 192.168.1.11  
  24. Connected to 192.168.1.11 (192.168.1.11).  
  25. 421 There are too many connected users,please try later.  


2.11 ftp——匿名用户限制某个用户有几个连接

[sql] view plain copy
  1. --第一步,修改配置文件,加入max_per_ip参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. #ftpd_banner="Welcome to mysite!!!----justdb"  
  9. #banner_file=/etc/vsftpd/my_banner  
  10. dirmessage_enable=yes  
  11. anon_mkdir_write_enable=yes  
  12. anon_other_write_enable=yes  
  13. anon_max_rate=1024000  
  14. max_clients=10  
  15. max_per_ip=2  
  16. --第二步,重启服务  
  17. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  18. Shutting down vsftpd:                                      [  OK  ]  
  19. Starting vsftpd for vsftpd:                                [  OK  ]  
  20. --第三步,测试。真实机建立2个连接后,建立第三个连接提示There are too many connections from your internet address,但是其他IP地址的用户不受影响  
  21. [root@larrywen ~]# ftp 192.168.1.11  
  22. [root@larrywen ~]# ftp 192.168.1.11  
  23. [root@larrywen ~]# ftp 192.168.1.11  
  24. Connected to 192.168.1.11 (192.168.1.11).  
  25. 421 There are too many connections from yourinternet address.  
  26.    
  27. [root@serv02 ~]# ftp 192.168.1.11  
  28. Connected to 192.168.1.11 (192.168.1.11).  
  29. 220 (vsFTPd 2.2.2)  
  30. Name (192.168.1.11:root): ftp  
  31. 331 Please specify the password.  
  32. Password:  
  33. 230 Login successful.  
  34. Remote system type is UNIX.  
  35. Using binary mode to transfer files.  

2.12 ftp——匿名用户修改上传文件的权限

[sql] view plain copy
  1. --第一步,修改配置文件,加入anon_umask参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. write_enable=yes  
  6. anon_upload_enable=yes  
  7. anon_root=/share  
  8. #ftpd_banner="Welcome to mysite!!!----justdb"  
  9. #banner_file=/etc/vsftpd/my_banner  
  10. dirmessage_enable=yes  
  11. anon_mkdir_write_enable=yes  
  12. anon_other_write_enable=yes  
  13. anon_max_rate=1024000  
  14. max_clients=10  
  15. max_per_ip=2  
  16. anon_umask=022  
  17. --第二步,重启服务  
  18. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  19. Shutting down vsftpd:                                      [ OK  ]  
  20. Starting vsftpd for vsftpd:                                [  OK  ]  
  21. --第三步,测试。上传文件,发现权限变为644  
  22. [root@serv02 ~]# ftp 192.168.1.11  
  23. Connected to 192.168.1.11 (192.168.1.11).  
  24. 220 (vsFTPd 2.2.2)  
  25. Name (192.168.1.11:root): ftp  
  26. 331 Please specify the password.  
  27. Password:  
  28. 230 Login successful.  
  29. Remote system type is UNIX.  
  30. Using binary mode to transfer files.  
  31. ftp> cd upload  
  32. 250-this is upload dir  
  33. 250 Directory successfully changed.  
  34. ftp> put aa01.txt  
  35. local: aa01.txt remote: aa01.txt  
  36. 227 Entering Passive Mode (192,168,1,11,149,59).  
  37. 150 Ok to send data.  
  38. 226 Transfer complete.  
  39. 6 bytes sent in 9.9e-05 secs (60.61Kbytes/sec)  
  40. ftp> ls aa01.txt  
  41. 227 Entering Passive Mode(192,168,1,11,47,44).  
  42. 150 Here comes the directory listing.  
  43. -rw-r--r--   1 14       50              6 Aug 13 14:09 aa01.txt  
  44. 226 Directory send OK.  
  45. ftp>  


2.13 ftp——匿名用户修改上传文件的所有者

[sql] view plain copy
  1. --第一步,查看上传文件的所有者,发现拥有者时ftp  
  2. [root@serv01 upload]# ll  
  3. total 281812  
  4. -rw-r--r--. 1 ftp ftp         6 Aug 13 22:09 aa01.txt  
  5. -rw-------. 1 ftp ftp 288570185 Aug 13 20:04RevolutionOS操作系统革命.rmvb  
  6. --第二步,创建用户  
  7. [root@serv01 vsftpd]# useradd larry  
  8. --第三步,修改配置文件,加入chown_uploads和chown_username参数  
  9. [root@serv01 vsftpd]# vim vsftpd.conf  
  10. [root@serv01 vsftpd]# cat vsftpd.conf  
  11. listen=yes  
  12. write_enable=yes  
  13. anon_upload_enable=yes  
  14. anon_root=/share  
  15. #ftpd_banner="Welcome to mysite!!!----justdb"  
  16. #banner_file=/etc/vsftpd/my_banner  
  17. dirmessage_enable=yes  
  18. anon_mkdir_write_enable=yes  
  19. anon_other_write_enable=yes  
  20. anon_max_rate=1024000  
  21. max_clients=10  
  22. max_per_ip=2  
  23. anon_umask=022  
  24. chown_uploads=yes  
  25. chown_username=larry  
  26. #第四步,重启服务  
  27. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  28. Shutting down vsftpd:                                      [  OK  ]  
  29. Starting vsftpd for vsftpd:                                [  OK  ]  
  30.    
  31. --第五步,上传文件,再次查看文件所有者,发现已经变化  
  32. [root@serv02 ~]# echo "hello">> aa02.txt  
  33. [root@serv02 ~]# ftp 192.168.1.11  
  34. Connected to 192.168.1.11 (192.168.1.11).  
  35. 220 (vsFTPd 2.2.2)  
  36. Name (192.168.1.11:root): ftp  
  37. 331 Please specify the password.  
  38. Password:  
  39. 230 Login successful.  
  40. Remote system type is UNIX.  
  41. Using binary mode to transfer files.  
  42. ftp> cd upload  
  43. 250-this is upload dir  
  44. 250 Directory successfully changed.  
  45. ftp> put aa02.txt  
  46. local: aa02.txt remote: aa02.txt  
  47. 227 Entering Passive Mode(192,168,1,11,143,83).  
  48. 150 Ok to send data.  
  49. 226 Transfer complete.  
  50. 6 bytes sent in 0.000114 secs (52.63Kbytes/sec)  
  51. ftp>  
  52. [root@serv01 upload]# ll *.txt  
  53. -rw-r--r--. 1 ftp   ftp 6 Aug 13 22:09 aa01.txt  
  54. -rw-------. 1 larryftp 6 Aug 13 22:15 aa02.txt  


三 ftp——授权用户

3.1 ftp——授权用户测试授权用户的简单使用

[sql] view plain copy
  1. --第一步,创建本地帐号  
  2. #使用本地帐号(用户名和密码)  
  3. [root@serv01 vsftpd]# useradd larry  
  4. [root@serv01 vsftpd]# passwd larry  
  5. [root@serv01 vsftpd]# useradd justdb  
  6. [root@serv01 vsftpd]# passwd justdb  
  7. [root@serv01 vsftpd]# id larry  
  8. uid=500(larry) gid=500(larry)groups=500(larry)  
  9. [root@serv01 vsftpd]# id justdb  
  10. uid=501(justdb) gid=501(justdb) groups=501(justdb)  
  11.    
  12. --第二步,修改配置文件  
  13. [root@serv01 vsftpd]# vim vsftpd.conf  
  14. [root@serv01 vsftpd]# cat vsftpd.conf  
  15. listen=yes  
  16. anonymous_enable=no  
  17. local_enable=yes  
  18. --第三步,重启服务  
  19. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  20. Shutting down vsftpd:                                      [  OK  ]  
  21. Starting vsftpd for vsftpd:                                [  OK  ]  
  22.    
  23. --第四步,测试。发现匿名用户和本地将帐号都不可以登录  
  24. [root@serv02 ~]# ftp 192.168.1.11  
  25. Connected to 192.168.1.11 (192.168.1.11).  
  26. 220 (vsFTPd 2.2.2)  
  27. Name (192.168.1.11:root): ftp  
  28. 331 Please specify the password.  
  29. Password:  
  30. 530 Login incorrect.  
  31. Login failed.  
  32. ftp> ls  
  33. 530 Please login with USER and PASS.  
  34. Passive mode refused.  
  35. ftp> exit  
  36. 221 Goodbye.  
  37. [root@serv02 ~]# ftp 192.168.1.11  
  38. Connected to 192.168.1.11 (192.168.1.11).  
  39. 220 (vsFTPd 2.2.2)  
  40. Name (192.168.1.11:root): larry  
  41. 331 Please specify the password.  
  42. Password:  
  43. 530 Login incorrect.  
  44. Login failed.  
  45. ftp>  
  46.    
  47.    
  48. #PAM:Plug Auth Modele 可插拔认证模块  
  49. #思路:将具体认证和具体的系统隔离,灵活  
  50. [root@serv01 upload]# ls /etc/pam.d/  
  51. chfn              fingerprint-auth-ac  passwd            reboot        runuser-l          sshd        su-l  
  52. chsh              halt                 password-auth     remote        smartcard-auth     ssh-keycat system-auth  
  53. config-util       login                password-auth-ac  rhn_register smartcard-auth-ac  su          system-auth-ac  
  54. crond             newrole              polkit-1          run_init      smtp               sudo       vsftpd  
  55. fingerprint-auth  other                poweroff          runuser       smtp.postfix       sudo-i  
  56. [root@serv01 upload]# cat /etc/pam.d/vsftpd  
  57. #%PAM-1.0  
  58. session   optional     pam_keyinit.so    force revoke  
  59. auth      required       pam_listfile.soitem=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed  
  60. auth      required       pam_shells.so  
  61. auth      include  password-auth  
  62. account   include   password-auth  
  63. session   required     pam_loginuid.so  
  64. session   include    password-auth  


3.2 ftp——授权用户解决授权用户不能登录的问题

[sql] view plain copy
  1. --第一步,修改配置文件,新加入pam_service_name参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. --第二步,重启服务  
  9. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  10. Shutting down vsftpd:                                      [  OK  ]  
  11. Starting vsftpd for vsftpd:                                [  OK  ]  
  12. --第三步,Serv02测试,使用larry登录,并输入对应的密码,发现登录成功,进入用户的家目录  
  13. [root@serv02 ~]# ftp 192.168.1.11  
  14. Connected to 192.168.1.11 (192.168.1.11).  
  15. 220 (vsFTPd 2.2.2)  
  16. Name (192.168.1.11:root): larry  
  17. 331 Please specify the password.  
  18. Password:  
  19. 230 Login successful.  
  20. Remote system type is UNIX.  
  21. Using binary mode to transfer files.  
  22. ftp>  
  23. ftp> pwd  
  24. 257 "/home/larry"  
  25. #进入家目录,拷贝文件  
  26. [root@serv01 upload]# cd /home/larry/  
  27. [root@serv01 larry]# ll  
  28. total 0  
  29. [root@serv01 larry]# cp/boot/initramfs-2.6.32-131.0.15.el6.x86_64.img . -rvf  
  30. `/boot/initramfs-2.6.32-131.0.15.el6.x86_64.img'-> `./initramfs-2.6.32-131.0.15.el6.x86_64.img'  
  31. #下载  
  32. ftp> get initramfs-2.6.32-131.0.15.el6.x86_64.img  
  33. local:initramfs-2.6.32-131.0.15.el6.x86_64.img remote:initramfs-2.6.32-131.0.15.el6.x86_64.img  
  34. 227 Entering Passive Mode(192,168,1,11,121,102).  
  35. 150 Opening BINARY mode data connection forinitramfs-2.6.32-131.0.15.el6.x86_64.img (12587318 bytes).  
  36. 226 Transfer complete.  
  37. 12587318 bytes received in 0.135 secs(93157.27 Kbytes/sec)  
  38. ftp> exit  
  39. 221 Goodbye.  
  40. [root@serv02 ~]# lsinitramfs-2.6.32-131.0.15.el6.x86_64.img  
  41. initramfs-2.6.32-131.0.15.el6.x86_64.img  


3.3 ftp——授权用户修改共享目录

[sql] view plain copy
  1. --第一步,修改配置文件,加入local_root参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root=/share  
  9. --第二步,重启服务  
  10. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  11. Shutting down vsftpd:                                      [  OK  ]  
  12. Starting vsftpd for vsftpd:                                [  OK  ]  
  13. --第三步,测试  
  14. [root@serv02 ~]# ftp 192.168.1.11  
  15. Connected to 192.168.1.11 (192.168.1.11).  
  16. 220 (vsFTPd 2.2.2)  
  17. Name (192.168.1.11:root): larry  
  18. 331 Please specify the password.  
  19. Password:  
  20. 230 Login successful.  
  21. Remote system type is UNIX.  
  22. Using binary mode to transfer files.  
  23. ftp> pwd  
  24. 257 "/share"  
  25. ftp>  


3.4 ftp——授权用户允许上传

[sql] view plain copy
  1. --第一步,修改配置文件,加入write_enable参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root=/share  
  9. write_enable=yes  
  10. --第二步,重启服务  
  11. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  12. Shutting down vsftpd:                                      [  OK  ]  
  13. Starting vsftpd for vsftpd:                                [  OK  ]  
  14. --第三步,测试,可以上传  
  15. [root@serv02 ~]# ftp 192.168.1.11  
  16. Connected to 192.168.1.11 (192.168.1.11).  
  17. 220 (vsFTPd 2.2.2)  
  18. Name (192.168.1.11:root): larry  
  19. 331 Please specify the password.  
  20. Password:  
  21. 230 Login successful.  
  22. Remote system type is UNIX.  
  23. Using binary mode to transfer files.  
  24. ftp> cd upload  
  25. 250 Directory successfully changed.  
  26. ftp> put aa01.txt  
  27. local: aa01.txt remote: aa01.txt  
  28. 227 Entering Passive Mode (192,168,1,11,190,171).  
  29. 150 Ok to send data.  
  30. 226 Transfer complete.  
  31. 6 bytes sent in 5.4e-05 secs (111.11Kbytes/sec)  
  32. ftp>  

3.5 ftp——授权用户——限制速度

[sql] view plain copy
  1. --第一步,修改配置文件,加入local_max_rate参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root=/share  
  9. write_enable=yes  
  10. local_max_rate=1024000  
  11. --第二步,重启服务  
  12. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  13. Shutting down vsftpd:                                      [  OK  ]  
  14. Starting vsftpd for vsftpd:                                [  OK  ]  
  15. --第三步,测试。  
  16. [root@larrywen ~]# ftp 192.168.1.11  
  17. Connected to 192.168.1.11 (192.168.1.11).  
  18. 220 (vsFTPd 2.2.2)  
  19. Name (192.168.1.11:root): larry  
  20. 331 Please specify the password.  
  21. Password:  
  22. 230 Login successful.  
  23. Remote system type is UNIX.  
  24. Using binary mode to transfer files.  
  25. ftp> cd upload  
  26. 250 Directory successfully changed.  
  27. ftp> put RevolutionOS操作系统革命.rmvb  
  28. local: RevolutionOS操作系统革命.rmvb remote: RevolutionOS操作系统革命.rmvb  
  29. 227 Entering Passive Mode(192,168,1,11,198,237).  
  30. 150 Ok to send data.  
  31. 126902272 bytes sent in 124 secs (1022.06Kbytes/sec)  
  32. #可以使用watch动态查看文件的增长  
  33. [root@serv01 upload]# watch ls -lh  


3.6 ftp——授权用户限制登录客户端数和每个IP的登录个数,同匿名用户

#max_clients=10

#max_per_ip=2

3.7 ftp——授权用户限制用户登录

[sql] view plain copy
  1. #root用户不能登录  
  2. [root@serv02 ~]# ftp 192.168.1.11  
  3. Connected to 192.168.1.11 (192.168.1.11).  
  4. 220 (vsFTPd 2.2.2)  
  5. Name (192.168.1.11:root): root  
  6. 331 Please specify the password.  
  7. Password:  
  8. 530 Login incorrect.  
  9. Login failed.  
  10.    
  11. --第一步,追加用户到ftpusers文件中  
  12. [root@serv01 vsftpd]# cat ftpusers  
  13. # Users that are not allowed to login via ftp  
  14. root  
  15. bin  
  16. daemon  
  17. adm  
  18. lp  
  19. sync  
  20. shutdown  
  21. halt  
  22. mail  
  23. news  
  24. uucp  
  25. operator  
  26. games  
  27. nobody  
  28. [root@serv01 vsftpd]# echo "justdb">> ./ftpusers  
  29. [root@serv01 vsftpd]# tail -n1 ftpusers  
  30. Justdb  
  31. --第二步,重启服务  
  32. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  33. Shutting down vsftpd:                                      [  OK  ]  
  34. Starting vsftpd for vsftpd:                                [  OK  ]  
  35. --第三步,测试  
  36. [root@serv02 ~]# ftp 192.168.1.11  
  37. Connected to 192.168.1.11 (192.168.1.11).  
  38. 220 (vsFTPd 2.2.2)  
  39. Name (192.168.1.11:root): justdb  
  40. 331 Please specify the password.  
  41. Password:  
  42. 530 Login incorrect.  
  43. Login failed.  

3.8 ftp——授权用户允许root用户登录

[sql] view plain copy
  1. [root@serv01 vsftpd]# vim ftpusers  
  2. [root@serv01 vsftpd]# head -n2 ftpusers  
  3. # Users that are not allowed to login via ftp  
  4. #root  
  5. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  6. Shutting down vsftpd:                                      [  OK  ]  
  7. Starting vsftpd for vsftpd:                                [  OK  ]  
  8.    
  9. [root@serv02 ~]# ftp 192.168.1.11  
  10. Connected to 192.168.1.11 (192.168.1.11).  
  11. 220 (vsFTPd 2.2.2)  
  12. Name (192.168.1.11:root): root  
  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(192,168,1,11,30,219).  
  20. 150 Here comes the directory listing.  
  21. drwxr-xr-x   2 0        0            4096 Aug 13 11:28 download  
  22. -rw-r--r--   1 0        0       12587318 Aug 13 11:11 initramfs-2.6.32-131.0.15.el6.x86_64.img  
  23. drwxrwxrwx   2 0        0            4096 Aug 13 15:04 upload  
  24. 226 Directory send OK.  

3.9 ftp——授权用户允许部分用户登录

[sql] view plain copy
  1. --第一步,修改配置文件  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root=/share  
  9. write_enable=yes  
  10. local_max_rate=1024000  
  11. #max_clients=10  
  12. #max_per_ip=2  
  13. userlist_enable=yes  
  14. userlist_deny=NO  
  15. --第二步,修改配置文件,把larry加到user_list中  
  16. [root@serv01 vsftpd]# vim user_list  
  17. [root@serv01 vsftpd]# tail -n1 user_list  
  18. larry  
  19. --第三步,重启服务  
  20. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  21. Shutting down vsftpd:                                      [  OK  ]  
  22. Starting vsftpd for vsftpd:                                [ OK  ]  
  23. --第四步,测试,发现justdb可以登录,larry用户不能登录  
  24. [root@serv02 ~]# ftp 192.168.1.11  
  25. Connected to 192.168.1.11 (192.168.1.11).  
  26. 220 (vsFTPd 2.2.2)  
  27. Name (192.168.1.11:root): justdb  
  28. 530 Permission denied.  
  29. Login failed.  
  30. ftp> exit  
  31. 221 Goodbye.  
  32. [root@serv02 ~]# ftp 192.168.1.11  
  33. Connected to 192.168.1.11 (192.168.1.11).  
  34. 220 (vsFTPd 2.2.2)  
  35. Name (192.168.1.11:root): larry  
  36. 331 Please specify the password.  
  37. Password:  
  38. 230 Login successful.  
  39. Remote system type is UNIX.  
  40. Using binary mode to transfer files.  

#不允许登录,直接写到ftpusers文件中

 

#这样的运用:假如有很多用户,都不允许他们登录,把他们写到ftpusers文件中,并且vsftpd.conf这样设置:userlist_enable=nouserlist_deny=YES(这个参赛不设置亦可);如果允许他们都能登录,那么把他们写到user_list文件中,并且vsftpd.conf这样设置:userlist_enable=yesuserlist_deny=NO

      

3.10 ftp——授权用户 chroot

[sql] view plain copy
  1. #chroot:没应用的时候。普通用户都可以进入根目录,下载敏感文件  
  2.         
  3. [root@serv01 vsftpd]#vim vsftpd.conf  
  4. --第一步,编辑配置文件  
  5. [root@serv01 vsftpd]# vim vsftpd.conf  
  6. [root@serv01 vsftpd]# cat vsftpd.conf  
  7. listen=yes  
  8. anonymous_enable=no  
  9. local_enable=yes  
  10. pam_service_name=vsftpd  
  11. local_root=/share  
  12. write_enable=yes  
  13. local_max_rate=1024000  
  14. #max_clients=10  
  15. #max_per_ip=2  
  16. #userlist_enable=yes  
  17. #userlist_deny=yes  
  18. chroot_list_enable=yes  
  19. #假如chroot_local_user为yes,那么chroot_list_file里的用户不能被chroot限制,没有在chroot_list_file里的用户被限制。  
  20. chroot_local_user=yes  
  21. chroot_list_file=/etc/vsftpd/chroot_list  
  22. #假如chroot_local_user为no,那么chroot_list_file里的用户能被chroot限制,没有在chroot_list_file里的用户不被限制。  
  23. #chroot_local_user=no  
  24. #chroot_list_file=/etc/vsftpd/chroot_list  
  25.    
  26. --第二步,新建chroot_list文件  
  27. [root@serv01 vsftpd]# vim chroot_list  
  28. [root@serv01 vsftpd]# cat chroot_list  
  29. larry  
  30.    
  31. --第三步,重启服务  
  32. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  33. Shutting down vsftpd:                                      [  OK  ]  
  34. Starting vsftpd for vsftpd:                                [  OK  ]  
  35.    
  36. --第四步,测试,larry用户没有被chroot限制,不能进入根目录;justdb用户被chroot限制,不能进入根,只能进入共享的目录  
  37. [root@serv02 ~]# ftp 192.168.1.11  
  38. Connected to 192.168.1.11 (192.168.1.11).  
  39. 220 (vsFTPd 2.2.2)  
  40. Name (192.168.1.11:root): larry  
  41. 331 Please specify the password.  
  42. Password:  
  43. 230 Login successful.  
  44. Remote system type is UNIX.  
  45. Using binary mode to transfer files.  
  46. ftp> pwd  
  47. 257 "/share"  
  48. ftp> cd /  
  49. 250 Directory successfully changed.  
  50. ftp> ls  
  51. 227 Entering Passive Mode(192,168,1,11,92,126).  
  52. 150 Here comes the directory listing.  
  53. dr-xr-xr-x   2 0        0            4096 Jul 22 16:55 bin  
  54. dr-xr-xr-x   5 0        0           1024 Jul 22 16:56 boot  
  55. drwxr-xr-x  15 0        0            3580 Aug 13 11:46 dev  
  56. drwxr-xr-x  73 0        0            4096 Aug 13 14:23 etc  
  57. drwxr-xr-x   4 0        0            4096 Aug 13 14:23 home  
  58. dr-xr-xr-x  12 0        0            8192 May 10 2011 iso  
  59. dr-xr-xr-x   8 0        0            4096 Jul 22 16:55 lib  
  60. dr-xr-xr-x   8 0        0           12288 Jul 22 16:55 lib64  
  61. drwx------   2 0        0           16384 Jul 22 16:54 lost+found  
  62. drwxr-xr-x   2 0        0            4096 Dec 04  2009 media  
  63. drwxr-xr-x   2 0        0            4096 Dec 04  2009 mnt  
  64. drwxr-xr-x   3 0        0            4096 Dec 04  2009 opt  
  65. dr-xr-xr-x  89 0        0               0 Aug 13 10:22 proc  
  66. dr-xr-x---   2 0        0            4096 Aug 13 15:44 root  
  67. dr-xr-xr-x   2 0        0            4096 Jul 22 16:56 sbin  
  68. drwxr-xr-x   7 0        0               0 Aug 13 10:22 selinux  
  69. drwxr-xr-x   4 0        0            4096 Aug 13 11:26 share  
  70. drwxr-xr-x   2 0        0            4096 Dec 04  2009 srv  
  71. drwxr-xr-x  13 0        0               0 Aug 13 10:22 sys  
  72. drwxrwxrwt   3 0        0            4096 Aug 13 15:29 tmp  
  73. drwxr-xr-x  13 0        0            4096 Jul 22 16:54 usr  
  74. drwxr-xr-x  18 0        0            4096 Aug 13 10:23 var  
  75. 226 Directory send OK.  
  76.    
  77. [root@serv02 ~]# ftp 192.168.1.11  
  78. Connected to 192.168.1.11 (192.168.1.11).  
  79. 220 (vsFTPd 2.2.2)  
  80. Name (192.168.1.11:root): justdb  
  81. 331 Please specify the password.  
  82. Password:  
  83. 230 Login successful.  
  84. Remote system type is UNIX.  
  85. Using binary mode to transfer files.  
  86. ftp> pwd  
  87. 257 "/"  
  88. ftp> cd /  
  89. 250 Directory successfully changed.  
  90. ftp> pwd  
  91. 257 "/"  
  92. ftp> ls  
  93. 227 Entering Passive Mode(192,168,1,11,208,89).  
  94. 150 Here comes the directory listing.  
  95. drwxr-xr-x   2 0        0            4096 Aug 13 11:28 download  
  96. -rw-r--r--   1 0        0        12587318 Aug 13 11:11initramfs-2.6.32-131.0.15.el6.x86_64.img  
  97. drwxrwxrwx   2 0        0            4096 Aug 13 15:04 upload  
  98. 226 Directory send OK.  


3.11 ftp——授权用户个性化设置(某个用户可以上传,其他用户不可以)

[sql] view plain copy
  1.  --第一步,修改vsftpd.conf配置文件,加入user_config_dir参数  
  2. [root@serv01 vsftpd]# vim vsftpd.conf  
  3. [root@serv01 vsftpd]# cat vsftpd.conf  
  4. listen=yes  
  5. anonymous_enable=no  
  6. local_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root=/share  
  9. #write_enable=yes  
  10. local_max_rate=1024000  
  11. #max_clients=10  
  12. #max_per_ip=2  
  13. #userlist_enable=yes  
  14. #userlist_deny=yes  
  15. chroot_list_enable=yes  
  16. chroot_local_user=yes  
  17. chroot_list_file=/etc/vsftpd/chroot_list  
  18. user_config_dir=/etc/vsftpd/user_conf  
  19.  --第二步,创建目录,并创建以用户名为文件名的文件  
  20. [root@serv01 vsftpd]# mkdir/etc/vsftpd/user_conf  
  21. [root@serv01 vsftpd]# ll user_conf/ -ld  
  22. drwxr-xr-x. 2 root root 4096 Aug 13 23:53user_conf/  
  23. [root@serv01 vsftpd]# cd user_conf/  
  24. [root@serv01 user_conf]# vim larry  
  25. [root@serv01 user_conf]# cat larry  
  26. write_enable=yes  
  27. --第三步,重启服务  
  28. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  29. Shutting down vsftpd:                                      [  OK  ]  
  30. Starting vsftpd for vsftpd:                                [  OK  ]  
  31.   --第四步,测试。发现larry用户可以上传,justdb用户不可以上传  
  32.  [root@serv02 ~]# ftp 192.168.1.11  
  33. Connected to 192.168.1.11 (192.168.1.11).  
  34. 220 (vsFTPd 2.2.2)  
  35. Name (192.168.1.11:root): larry  
  36. 331 Please specify the password.  
  37. Password:  
  38. 230 Login successful.  
  39. Remote system type is UNIX.  
  40. Using binary mode to transfer files.  
  41. ftp> cd upload  
  42. 250 Directory successfully changed.  
  43. ftp> !ls  
  44. aa01.txt aa02.txt  anaconda-ks.cfg  initramfs-2.6.32-131.0.15.el6.x86_64.img  install.log install.log.syslog  -l  
  45. ftp> put aa01.txt  
  46. local: aa01.txt remote: aa01.txt  
  47. 227 Entering Passive Mode(192,168,1,11,214,219).  
  48. 150 Ok to send data.  
  49. 226 Transfer complete.  
  50. 6 bytes sent in 0.0001 secs (60.00Kbytes/sec)  
  51. ftp> exit  
  52. 221 Goodbye.  
  53. [root@serv02 ~]# ftp 192.168.1.11  
  54. Connected to 192.168.1.11 (192.168.1.11).  
  55. 220 (vsFTPd 2.2.2)  
  56. Name (192.168.1.11:root): justdb  
  57. 331 Please specify the password.  
  58. Password:  
  59. 230 Login successful.  
  60. Remote system type is UNIX.  
  61. Using binary mode to transfer files.  
  62. ftp> cd upload  
  63. 250 Directory successfully changed.  
  64. ftp> put aa02.txt  
  65. local: aa02.txt remote: aa02.txt  
  66. 227 Entering Passive Mode(192,168,1,11,183,231).  
  67. 550 Permission denied.  
  68.    
  69. #注意:局部优先,也就是vsftpd.conf中包含write_enable=yes,且用户中#write_enable=no,那么该用户仍不能上传。  

3.12 ftp——授权用户——局部优先测试

[sql] view plain copy
  1. --第一步,修改配置文件,把write_enable参数加入,把larry文件中改为no  
  2. [root@serv01 vsftpd]# cat vsftpd.conf  
  3. listen=yes  
  4. anonymous_enable=no  
  5. local_enable=yes  
  6. pam_service_name=vsftpd  
  7. local_root=/share  
  8. write_enable=yes  
  9. local_max_rate=1024000  
  10. #max_clients=10  
  11. #max_per_ip=2  
  12. #userlist_enable=yes  
  13. #userlist_deny=yes  
  14. chroot_list_enable=yes  
  15. chroot_local_user=yes  
  16. chroot_list_file=/etc/vsftpd/chroot_list  
  17. user_config_dir=/etc/vsftpd/user_conf  
  18. [root@serv01 vsftpd]# cat user_conf/larry  
  19. write_enable=no  
  20. --第二步,重启服务  
  21. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  22. Shutting down vsftpd:                                      [  OK  ]  
  23. Starting vsftpd for vsftpd:                                [  OK  ]  
  24. --第三步,测试。larry用户不能上传,justdb用可以上传  
  25. [root@serv02 ~]# ftp 192.168.1.11  
  26. Connected to 192.168.1.11 (192.168.1.11).  
  27. 220 (vsFTPd 2.2.2)  
  28. Name (192.168.1.11:root): larry  
  29. 331 Please specify the password.  
  30. Password:  
  31. 230 Login successful.  
  32. Remote system type is UNIX.  
  33. Using binary mode to transfer files.  
  34. ftp> cd upload  
  35. 250 Directory successfully changed.  
  36. ftp> put aa01.txt  
  37. local: aa01.txt remote: aa01.txt  
  38. 227 Entering Passive Mode(192,168,1,11,147,45).  
  39. 550 Permission denied.  
  40. ftp> exit  
  41. 221 Goodbye.  
  42. [root@serv02 ~]# ftp 192.168.1.11  
  43. Connected to 192.168.1.11 (192.168.1.11).  
  44. 220 (vsFTPd 2.2.2)  
  45. Name (192.168.1.11:root): justdb  
  46. 331 Please specify the password.  
  47. Password:  
  48. 230 Login successful.  
  49. Remote system type is UNIX.  
  50. Using binary mode to transfer files.  
  51. ftp> cd upload  
  52. 250 Directory successfully changed.  
  53. ftp> put aa02.txt  
  54. local: aa02.txt remote: aa02.txt  
  55. 227 Entering Passive Mode(192,168,1,11,90,8).  
  56. 150 Ok to send data.  
  57. 226 Transfer complete.  
  58. 6 bytes sent in 9.1e-05 secs (65.93Kbytes/sec)  

3.13 ftp——授权用户虚拟帐号

 

[sql] view plain copy
  1. [root@serv01 vsftpd]# cd/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS  
  2. [root@serv01 VIRTUAL_USERS]# ll  
  3.    
  4. --第一步,创建真实用户larry并设定密码  
  5. [root@serv01 vsftpd]# useradd larry  
  6. [root@serv01 vsftpd]# passwd larry  
  7. --第二步,创建logins.txt文件,并添加内容如下  
  8. [root@serv01 ~]# vim logins.txt  
  9. [root@serv01 ~]# cat logins.txt  
  10. #注意:一行用户名,一行密码;交替使用  
  11. larry01  
  12. 123456  
  13. larry02  
  14. 123456  
  15. larry03  
  16. 123456  
  17. larry04  
  18. 123456  
  19. --第三步,创建login.db文件  
  20. [root@serv01 ~]# db_load -T -t hash -flogins.txt /etc/vsftpd/login.db  
  21. [root@serv01 ~]# cd /etc/vsftpd/  
  22. --第四步,修改权限  
  23. [root@serv01 vsftpd]# chmod 600 login.db  
  24. --第五步,创建PAM文件,加入如下内容(可以到/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/README文件复制),注意因为我使用的系统是64位,所以需要把lib改成lib64,不然找不到这个模块文件  
  25. [root@serv01 vsftpd]# vim /etc/pam.d/ftp  
  26. [root@serv01 vsftpd]# cat /etc/pam.d/ftp  
  27. auth required /lib/security/pam_userdb.sodb=/etc/vsftpd/login  
  28. account required /lib/security/pam_userdb.sodb=/etc/vsftpd/login  
  29. [root@serv01 vsftpd]# ls/lib/security/pam_userdb.so  
  30. ls: cannot access/lib/security/pam_userdb.so: No such file or directory  
  31. [root@serv01 vsftpd]# vim /etc/pam.d/ftp  
  32. [root@serv01 vsftpd]# ls/lib64/security/pam_userdb.so  
  33. /lib64/security/pam_userdb.so  
  34. [root@serv01 vsftpd]# cat /etc/pam.d/ftp  
  35. auth required /lib64/security/pam_userdb.sodb=/etc/vsftpd/login  
  36. account required/lib64/security/pam_userdb.so db=/etc/vsftpd/login  
  37. --第六步,修改vsftpd.conf配置文件  
  38. [root@serv01 vsftpd]# vim vsftpd.conf  
  39. [root@serv01 vsftpd]# cat vsftpd.conf  
  40. listen=yes  
  41. anonymous_enable=no  
  42. local_enable=yes  
  43. pam_service_name=ftp  
  44. local_root=/share  
  45. write_enable=yes  
  46. local_max_rate=1024000  
  47. #max_clients=10  
  48. #max_per_ip=2  
  49. #userlist_enable=yes  
  50. #userlist_deny=yes  
  51. chroot_list_enable=yes  
  52. chroot_local_user=yes  
  53. chroot_list_file=/etc/vsftpd/chroot_list  
  54. user_config_dir=/etc/vsftpd/user_conf  
  55. guest_enable=yes  
  56. guest_username=larry  
  57. --第七步,重启服务  
  58. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  59. Shutting down vsftpd:                                      [  OK  ]  
  60. Starting vsftpd for vsftpd:                                [  OK  ]  
  61. --第八步,测试,注意使用虚拟用户登录,比如larry01 larry02  
  62. [root@serv02 ~]# ftp 192.168.1.11  
  63. Connected to 192.168.1.11 (192.168.1.11).  
  64. 220 (vsFTPd 2.2.2)  
  65. Name (192.168.1.11:root): larry01  
  66. 331 Please specify the password.  
  67. Password:  
  68. 230 Login successful.  
  69. Remote system type is UNIX.  
  70. Using binary mode to transfer files.  
  71. ftp> exit  
  72. 221 Goodbye.  
  73. [root@serv02 ~]# ftp 192.168.1.11  
  74. Connected to 192.168.1.11 (192.168.1.11).  
  75. 220 (vsFTPd 2.2.2)  
  76. Name (192.168.1.11:root): larry02  
  77. 331 Please specify the password.  
  78. Password:  
  79. 230 Login successful.  
  80. Remote system type is UNIX.  
  81. Using binary mode to transfer files.  
  82. ftp> exit  
  83. 221 Goodbye.  
  84. --第九步,验证。可以发现up01和up02在真实系统中不存在  
  85. [root@serv01 vsftpd]# ip up01  
  86. Object "up01" is unknown, try"ip help".  
  87. [root@serv01 vsftpd]# ip larry01  
  88. Object "larry01" is unknown, try"ip help".  
  89. [root@serv01 vsftpd]# ip larry02  
  90. Object "larry02" is unknown, try"ip help".  

四 ftp——实验

 

需求

       /share:匿名用户和账户访问都可以下载

       /share/upload:匿名用户不能进入(下载),授权用户(up01 up02 up03)可以下载,只有up01可以上传

       Samba:匿名帐号和授权账户不可以访问

      

解决

[sql] view plain copy
  1. --第一步,安装vsftp  
  2. [root@serv01 dhcp]# yum install vsftpd*-y  
  3. --第二步,创建目录,share目录权限为755,upload权限为777  
  4. [root@serv01 vsftpd]# mkdir /share  
  5. [root@serv01 vsftpd]# mkdir /share/upload  
  6. [root@serv01 vsftpd]# chmod 755 /share  
  7. [root@serv01 vsftpd]# chmod 777 /share/upload  
  8. --第三步,创建用户,并设置密码  
  9. [root@serv01 user_conf]# useradd up01  
  10. [root@serv01 user_conf]# passwd up01  
  11. [root@serv01 user_conf]# useradd up02  
  12. [root@serv01 user_conf]# passwd up02  
  13. [root@serv01 user_conf]# useradd up03  
  14. [root@serv01 user_conf]# passwd up03  
  15.    
  16. --第四步,修改配置文件,配置如下  
  17. [root@serv01 vsftpd]# mv vsftpd.confvsftpd.conf.bak  
  18.    
  19. [root@serv01 vsftpd]# mv vsftpd.confvsftpd.conf.bak  
  20. [root@serv01 vsftpd]# echo "" >vsftpd.conf  
  21.    
  22. [root@serv01 vsftpd]# vim vsftpd.conf  
  23. [root@serv01 vsftpd]# cat vsftpd.conf  
  24. listen=yes  
  25. anon_upload_enable=yes  
  26. anon_root=/share  
  27. local_enable=yes  
  28. anonymous_enable=yes  
  29. pam_service_name=vsftpd  
  30. local_root=/share/upload  
  31. user_config_dir=/etc/vsftpd/user_conf  
  32.    
  33. --第五步,创建user_conf目录,新建up01 up02 up03文件内容如下  
  34. [root@serv01 ~]# mkdir /etc/vsftpd/user_conf  
  35. [root@serv01 ~]# cd /etc/vsftpd/user_conf  
  36.    
  37.        [root@serv01 user_conf]# vim up01  
  38. [root@serv01 user_conf]# vim up02  
  39. [root@serv01 user_conf]# vim up03  
  40.    
  41. [root@serv01 user_conf]# cat up01  
  42. write_enable=yes  
  43. [root@serv01 user_conf]# cat up02  
  44. write_enable=no  
  45. [root@serv01 user_conf]# cat up03  
  46. write_enable=no  
  47. --第六步,重启服务  
  48. [root@serv01 vsftpd]# /etc/init.d/vsftpdrestart  
  49. Shutting down vsftpd:                                      [  OK  ]  
  50. Starting vsftpd for vsftpd:                                [  OK  ]  
  51.    
  52. --第七步,测试  

 

其他实现方式

[sql] view plain copy
  1. [root@serv01 vsftpd]# cat vsftpd.conf  
  2. listen=yes  
  3. anon_upload_enable=yes  
  4. anon_root=/share  
  5. local_enable=yes  
  6. anonymous_enable=yes  
  7. pam_service_name=vsftpd  
  8. local_root= /upload  
  9. user_config_dir=/etc/vsftpd/user_conf  
  10.    
  11. #/share/upload/目录权限为770或者744,而且所属组为uplook,up01、up02、up03三个用户均属于这个组。通过组和目录的权限控制部分权限。  
  12. [root@serv01 vsftpd]# chmod 770 /share/upload  
  13.    
  14. #其他一致  


五 参考资料

 

ftp——百度百科

vsftpd——百度百科

tftp——百度百科

0 0