手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

基于MySQL架设FTP服务器

[日期:2012-08-11] 来源:Linux社区  作者:xinghuiru [字体:大 中 小]

 二、为每个虚拟用户定制权限

  1. 实现:magedu 可上传文件  marion 只有访问权限 
  2. user_config_dir 指令  可以实现让我们指定一个目录,在这个目录中为每一个用户创建一个同名的配置文件,用于定义这个用户在访问目录的  
  3. 时候自己所独有的权限  
  4. #cd /etc/vsftpd  
  5. #mkdir virusers //创建一个目录,而后为用户建立对应的文件 
  6. #cd virusers  
  7. #vim  magedu  
  8. 添加    
  9. anon_upload_enable=YES 
  10. anon_mkdir_write_enable=NO 
  11. anon_other_write_enable=NO         有上传权限没有删除权限  
  12. #vim marion  
  13. 添加    
  14. anon_upload_enable=NO 
  15. anon_mkdir_write_enable=NO 
  16. anon_other_write_enable=NO 
  17.  
  18. 编辑 /etc/vsftpd/vsftpd.conf  
  19. 添加  
  20.     user_config_dir=/etc/vsftpd/virusers  
  21. 测试:  
  22. #ftp localhost  
  23. Name (localhost:root): magedu  
  24. 331 Please specify the password.  
  25. Password:  
  26. 230 Login successful.  
  27. Remote system type is UNIX.  
  28. Using binary mode to transfer files.  
  29. ftp> put inittab  
  30. local: inittab remote: inittab  
  31. 227 Entering Passive Mode (127,0,0,1,250,166)  
  32. 150 Ok to send data.  
  33. 226 File receive OK.  
  34. 1666 bytes sent in 0.017 seconds (98 Kbytes/s)   //上传成功
  35. ftp> ls     
  36. 227 Entering Passive Mode (127,0,0,1,46,110)  
  37. 150 Here comes the directory listing.  
  38. -rw-------    1 503      503           608 Aug 04 10:22 fstab  
  39. -rw-------    1 503      503          1666 Aug 04 10:55 inittab  
  40. 226 Directory send OK.  
  41. ftp> get fstab  
  42. local: fstab remote: fstab  
  43. 227 Entering Passive Mode (127,0,0,1,223,8)  
  44. 550 Failed to open file.   //不可以下载
  45. ftp> bye  
  46. 同样方法测试mrion用户  
  47. 不可以删除、上传 

三、系统用户和虚拟用户同时可以访问 useradd -r -M gentoo  

  1. #useradd -r gentoo
  2. #passwd gentoo  
  3. RedHat   //密码为redhat
  4. #ftp localhost //用gentoo登陆 失败  
  5. # tail -1 /var/log/secure   
  6. Aug  4 19:08:20 station11 vsftpd: pam_MySQL - SELECT returned no result.  
  7. //到mysql中去找了,当然找不到了   系统用户用的是/etc/pam.d/vsftpd  虚拟用户用的是/etc/pam.d/vsftpd.my  将两个文件整合都一起  
  8. #vim /etc/vsftpd/vsftpd  
  9. 将内容改为如下形式,将/etc/pam.d/vsftpd.my中的内容添加到此文件中  
  10. #session    optional     pam_keyinit.so    force revoke  
  11. auth    sufficient /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 
  12. auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed 
  13. auth       required     pam_shells.so  
  14. auth       include      system-auth  
  15. account sufficient /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 
  16. account    include      system-auth  
  17. session    include      system-auth  
  18. session    required     pam_loginuid.so  
  19. 而后编辑配置文件/etc/vsftpd/vsftpd.conf  
  20. 将pam_service_name=vsftpd.my  改为 pam_service_name=vsftpd 
  21.  
  22. 重启服务  
  23. #service vsftpd restart  
  24.  
  25. 测试:  
  26. [root@sut20 ~]# ftp localhost  
  27. Connected to localhost.localdomain.  
  28. 220 (vsFTPd 2.0.5)  
  29. 530 Please login with USER and PASS.  
  30. 530 Please login with USER and PASS.  
  31. KERBEROS_V4 rejected as an authentication type  
  32. Name (localhost:root): magedu  //虚拟用户登陆
  33. 331 Please specify the password.  
  34. Password:  
  35. 230 Login successful.  
  36. Remote system type is UNIX.  
  37. Using binary mode to transfer files.  
  38. ftp> ls   
  39. 227 Entering Passive Mode (127,0,0,1,239,100)  
  40. 150 Here comes the directory listing.  
  41. -rw-------    1 503      503           608 Aug 04 10:22 fstab  
  42. -rw-------    1 503      503          1666 Aug 04 10:55 inittab  
  43. 226 Directory send OK.  
  44.  
  45. [root@sut20 ~]# ftp localhost  
  46. Connected to localhost.localdomain.  
  47. 220 (vsFTPd 2.0.5)  
  48. 530 Please login with USER and PASS.  
  49. 530 Please login with USER and PASS.  
  50. KERBEROS_V4 rejected as an authentication type  
  51. Name (localhost:root): gentoo  //系统用户登陆
  52. 331 Please specify the password.  
  53. Password:  
  54. 230 Login successful.  
  55. Remote system type is UNIX.  
  56. Using binary mode to transfer files.  
  57. ftp> ls   
  58. 227 Entering Passive Mode (127,0,0,1,239,100)  
  59. 150 Here comes the directory listing.  
  60. -rw-------    1 503      503           608 Aug 04 10:22 fstab  
  61. -rw-------    1 503      503          1666 Aug 04 10:55 inittab  
  62. 226 Directory send OK. 

四、FTP服务器的访问控制

例如:禁止vsftp为172.16.100.200访问  

 

  1. #vim /etc/hosts.deny  
  2. 添加  
  3. vsftpd: ALL EXCEPT 172.16. EXCEPT 172.16.100.150  
  4.  
  5. 测试机地址为172.16.100.150  
  6. ftp 172.16.20.1  
  7. 421 Service not available  
  8. User <172.16.20.1:<none>>;  //访问失败

综上:实现了基于mysql数据库架设FTP服务器的相关配置

linux
相关资讯       ftp服务器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款