红联Linux门户
Linux帮助

Linux下FTP虚拟用户的使用配置

发布时间:2009-10-14 14:44:31来源:红联作者:bdsnmp
Linux的FTP服务支持3种用户:

1.匿名帐户

2.本地帐户

3.虚拟用户

为什么要使用虚拟用户:

匿名帐户可以很好的保证FTP服务器的安全性,但是,对匿名用户的权限管理不够灵活.如果想对访问FTP的帐户给予更多的权限,就可以用本地帐户来实现.但是,本地帐户默认情况下是可以登陆Linux系统的,这样对Linux系统来说是一个安全隐患.那么怎么能在灵活的赋予FTP用户权限的前提下,保证FTP服务器乃至整个Linux系统的安全呢?使用虚拟用户就是一种解决办法.

下面,我们就一起来学习,该怎样在Linux下配置FTP服务器的虚拟用户.

开始配置前,让我们先大概了解下FTP虚拟用户的工作原理:

虚拟用户,顾名思义,并不是一个合法的Linux系统帐户,但是他可以用来登陆该系统上运行的FTP服务器.

当用户在连接上FTP服务器后,会被要求输入用户名和密码.FTP服务器在拿到这个用户名和密码后,会调用相应的PAM认证模块对,和系统中的FTP认证文件进行相比较.如果该用户名和密码与FTP认证文件中的某条记录相符,就通过认证,然后该帐户就被映射成一个Linux下的本地帐户,然后根据使用该本地帐户对FTP资源进行访问.否则则断开该连接请求.

了解了FTP虚拟用户的工作原理后,我们就可以开始配置FTP虚拟用户了.

整个过程可以分这几个步骤:

1.准备一个虚拟用户的口令库文件.该文件中保存的用户名和密码是用户连接FTP服务器时,需要输入的用户名和密码.文件可以自己创建,位置无关紧要,文件格式为:奇数行为用户名,偶数行为密码.

例如:touch login.txt //创建一个名为login.txt的虚拟用户口令库文件

vi login.txt //编辑该口令库文件

mike //虚拟用户mike

123 //虚拟用户mike的密码

john //虚拟用户john

321 //虚拟用户john的密码

保存退出.

2.用刚才建立的虚拟用户口令库文件生成FTP服务器的认证文件.该认证文件是一个被加密后的密文.PAM在调用相应的认证模块后,会对从FTP服务器发来的用户名和密码进行加密,然后在跟该文件进行对比,发现相符条目后,登陆用户才会被允许登陆.

db_load -T -t hash -f login.txt /etc/vsftpd/vsftpd_login.db

//在运行该命令前,别忘记安装db4-utils软件包,该包包含有db_load命令等.关于该命令的使用不在本文讨论范围内.其中-f参数后跟的为刚才创建的虚拟用户口令库文件.最后的路径为生成的FTP认证文件的存放位置.

为了进一步保证安全,可以将该FTP认证文件的权限设置为600.

3.建立虚拟用户所需要的PAM配置文件.由于FTP服务器在接受到用户的用户名和口令后会调用PAM认证,所以我们还要创建虚拟用户的PAM配置文件.

我们将该文件保存在/etc/pam.d目录下,文件名暂时取为:vsftpd.这里要注意一点就是,该文件名要与FTP服务主配置文件(/etc/vsftpd/vsftpd.conf)中的pam_service_name=vsftpd选项的选项值相同.

创建好该文件后,将下面的内容加入到该文件中:

auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

改好后,保存退出.注意3个红色文件的文件名.该3个文件为1个文件,只不过在使用中写法不同.

4.由于用户在通过PAM的认证后要被映射成一个本地用户,所以我们还要建立一个本地用户供虚拟用户使用.

我们只需要对该本地用户赋予FTP主目录的适当访问权限就行.即使FTP服务器遭到攻击,这个本地用户也没有访问其他目录的权限,相对比较安全一些.

useradd -d /home/ftpsite virtual //用户名为virtual,主目录为FTP的根

chmod 700 /home/ftpsite //将其权限设置为700,可以根据实际情形进行修改

5.在FTP的主配置文件中,启用FTP虚拟用户.增加如下选项即可:

guest_enable=YES

guest_username=virtual //将虚拟用户映射成本地的哪个用户.这里用的是virtual,刚才建

立的那个用户.

pam_service_name=/etc/vsftpd/vsftpd //切记要修改该项的值

6.配置到这里就完成了,别忘记重启FTP服务进行测试.

7.为不同的虚拟用户分配权限

默认情况下,虚拟用户拥有相同的权限,就是virtual的权限,我们可以根据实际需求对不同的虚拟用户分配权限.

首先在FTP的主配置文件中加一个选项:

user_config_dir=/etc/vsftpd_user_conf //文件名和路径都可以自己定义

然后创建该目录.

mkdir /etc/vsftpd_user_conf

下面就可以在该目录下编辑不同虚拟用户的权限配置文件了,比如要对mike编辑其权限.

touch mike //建立mike的权限文件.文件名要与虚拟用户名相同

可以根据实际需求为该文件添加下面的选项和值:

anon_world_readable_only=NO //表示用户可以浏览FTP目录和下载文件

anon_upload_enable=YES //表示用户可以上传文件

anon_mkdir_write_enable=YES //表示用户有创建和删除目录的权限

anon_other_write_enable=YES //表示用户具有文件改名和删除文件的权限



到这里,虚拟用户就算完成配置完成了.
文章评论

共有 29 条评论

  1. zlyzx1000 于 2013-06-04 14:33:57发表:

    :0w5ty(1

  2. zhangjp_jp 于 2013-03-27 13:49:37发表:

    跟着学习学习,感谢

  3. 石头玩家 于 2013-01-16 13:49:43发表:

    此贴必火!(q):s

  4. zhangasd123 于 2013-01-13 20:38:51发表:

    楼主讲的很详细,鼓掌!!!!

  5. 12700696 于 2012-12-25 11:10:10发表:

    :0)1

  6. jhyeqf 于 2012-12-19 22:19:05发表:

    谢谢楼主,学习啦1

  7. andrea 于 2012-12-14 23:20:07发表:

    很强大

  8. 阿莱82 于 2012-08-08 08:23:18发表:

    学习了,谢谢

  9. uwif8144 于 2012-07-07 07:45:34发表:

    ?accordingly, to win the national popular vote, a candidate must appeal to the large majority of americans who do not live in these urban centers. at the state level, candidates do not spend all their time and resources only in urban centers. in 2010, texas governor rick perry was re-elected by 13 percentage points, despite being overwhelmingly defeated in the state's two largest cities: houston and dallas. in fact, these two loan star cities are two of the largest populated u.s. cities. in new york, george pataki served three terms as governor despite the fact that he was wiped out in the nation's largest city, new york city. finally, california has elected four governors in the last 46 years who did not even come close to carrying the state's largest city, los angeles.
    lewis is correct when he opines: "a republic does not rest on pure majority (mob?) rule. it incorporates various checks and balances to filter the majority and protect the minority."
    yet the npvi in no way establishes "mob rule." the template for the governance system that the founding fathers established came from the roman republic. under the roman system, the people do not directly govern themselves. instead, they select fellow citizens to represent them, and these representatives in turn determine who will hold the office of the presidency. under "mob rule" the citizenry would vote on the issues themselves and the majority vote would decide the outcome. this is diametrically opposed to what the npvi is advocating.

  10. guhaooo 于 2012-06-22 20:55:31发表:

    感谢分享 不过感觉还是pdf用的时候正规些

  11. helloluxinyi 于 2012-02-05 12:18:43发表:

    {:2_91:}

  12. pbb7771930 于 2012-02-04 13:31:34发表:

    好好学习,天天向上

  13. jogahou_xym 于 2011-12-20 20:25:39发表:

    学习了,谢谢!

  14. lsj 于 2011-12-15 14:14:44发表:

    学习!!

  15. yjh277 于 2011-12-10 12:12:55发表:

    学习

  16. lsff 于 2011-11-07 21:12:57发表:

    学习了。。。

  17. hhj_321 于 2011-11-01 12:11:31发表:

    先收藏起来了

  18. haoge512 于 2011-10-31 22:19:50发表:

  19. qamallan 于 2011-03-28 13:41:14发表:

    不错,支持

  20. yangjiancsdn 于 2011-03-25 23:41:51发表:

    好贴!!!

  21. q7262395 于 2011-03-25 14:31:18发表:

    不错的技术,学习了,正好用上

  22. weixiaoyu111 于 2011-01-04 13:10:13发表:

    为为为wwwwwwwww

  23. lklangzi 于 2010-02-06 09:23:13发表:

    学习中

  24. liaolily 于 2010-01-29 21:58:56发表:

    1# bdsnmp


    Thanks!

  25. read 于 2010-01-28 16:39:58发表:

    了解一下!很详细!

  26. wAe]levis 于 2010-01-28 15:12:32发表:

    (5ty(

  27. yong009003 于 2010-01-19 13:33:29发表:

    了解一下!:0()w(1

  28. zln060618 于 2009-10-14 18:22:49发表:

    {:2_92:}

  29. weimian 于 2009-10-14 15:13:43发表:

    学习一下