`
dxflygao
  • 浏览: 66012 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

vsftpd 配置

 
阅读更多
http://down.51cto.com51CTO技术资料下载中心
关于vsftpd 虚拟用户通过PAM.d的认证.
(1) pam.d 认证机制是属于第三方安全认证机制,它提供认证接口,供使用。
(2) 制作DB文件(user-pwd) .(注意:转入到 /etc/vsftpd/目录下了)
A)先在写一个 account.txt :
  Lisi_ftp #奇数行用户名
  Lisi     #偶数行密码
B) db_load  -T –t hash -f account.txt accountabc.db(该文件下面要用到)

(3) 在 /etc/pam.d/中配置认证。注意的是,该目录下的配置文件名称与服务的名称相同,如我们配的是vsftpd ,则我们的配置文件名就为 vsftpd(该名称也会在vsftpd.conf中用到)。
在配置文件中,将原来的配置注释掉(但这样导致本地用户无法使用FTP,没有找到更好的解决办法)。
在配置文件中,添加两行:
auth      required     /lib/security/pam_userdb.so   db=/etc/vsftpd/accountabc
account    required     /lib/security/pam_userdb.so   db=/etc/vsftpd/accountabc
%%说明:accountabc 是我生成的DB文件(user-pwd),具体的操作在上面已经讲到。
(4)配置vsftpd.conf。这个配置项比较多,可以参考一些网上说明来进行
但是要使用虚拟用户,必须要配置以下几项:
guest_enable=YES
guest_username=xxxftp #该用户名是建立的linux用户,虚拟用户都通过他来实现登录
pam-service-name=vsftpd #上述提到的配置文件
(5)为每个虚拟用户配置相应的私有目录
在vsftpd.conf文件中添加一行:user_config_dir=/etc/vsftpd/userconfig/
(这个是虚拟用户目录使用的父目录这是自定义的)
然后,在userconfig/下面为每个虚拟用户配置专有配置文件,文件名为虚拟用户名,如lisi_ftp。在lisi_ftp文件中添加:local_root= /home/developteam/ftp/lisi/
%%说明:对于/home/developteam/ftp/lisi/ 中的lisi目录,要chmod  755,chown xxxftp

=============================
使用PYTHON 写的 自动生成 ftp用户设置的代码:
#!/usr/bin/env python

import subprocess
import os
infile = open('/etc/vsftpd/userconfig/list','r')
outfile = open('/etc/vsftpd/userconfig/ftplist','w')
lines = infile.readlines(100)
for line in lines:
    equSqu = line.find("=")
    username = line[:equSqu]
#generate ftp user private directory
    os.mkdir('/home/developteam/ftp/'+username)
# chmod the new directory  named $username  to 755 ,and chown ftp
    subprocess.call('chown ftp:ftp /home/developteam/ftp/'+username,shell=True)
    subprocess.call('chmod 755 /home/developteam/ftp/'+username,shell=True)
# create and write user's local_root to the ftp single configure file :  usrfile 
    usrfile = open('/etc/vsftpd/userconfig/'+username,'a+')
    usrfile.write("local_root=/home/developteam/ftp/"+username + "/")
    usrfile.flush()
    usrfile.close()
    userpwd = line[equSqu+1:]
    outfile.write(username + "\n") 
    outfile.write(userpwd)
outfile.flush()
outfile.close()
infile.close()
# generate the user-pwd  db file
subprocess.call('db_load -T -t hash -f /etc/vsftpd/userconfig/ftplist  /etc/vsftpd/account.db',shell=True)



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics