CentOS7-VSFTPD-虚拟用户(virtual-user)-设置

1, 依赖安装包(Install):

    # yum install vsftpd                      // this is the major software for ftp service
    # yum install db4-utils                   // tools for setup virtual user database

2, 配置设置(Configure):    

 #vim /etc/vsftpd/vsftpd.conf  
    allow_writeable_chroot=YES    
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    anon_mkdir_write_enable=YES
    dirmessage_enable=YES
    xferlog_enable=YES
    connect_from_port_20=YES
    xferlog_file=/var/log/vsftp.log
    xferlog_std_format=YES
    vsftpd_log_file=/var/log/vsftpd.log
    chroot_list_enable=YES
    listen=YES
    pam_service_name=vsftpd-virtual
    userlist_deny=NO
    userlist_enable=YES
    tcp_wrappers=YES
    guest_enable=YES
    virtual_use_local_privs=YES
    local_root=/var/ftp/pub  
    chroot_local_user=YES
    hide_ids=YES
    anon_other_write_enable=YES
    user_config_dir=/etc/vsftpd/user_config

3, 创建用户名密码文本 /etc/vsftpd/virtual-users.txt (单行为用户名,双行为密码)

    am313                                         //the virtual username                                                      
    123456                                       //the virtual user passwd

4, 用db4加密该文本后生成一个virtual-users.db4,记得备份txt文本后删除该文件

#db_load -T -t hash -f /etc/vsftpd/virtual-users.txt /etc/vsftpd/virtual-users.db

5, 修改 /etc/vsftpd/user_list 文件,注释掉的都不能访问该ftp,在最后添加你所创建的虚拟用户

# vim user_list
    # vsftpd userlist
    # If userlist_deny=NO, only allow users in this file
    # If userlist_deny=YES (default), never allow users in this file, and
    # do not even prompt for a password.
    # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
    # for users that are denied.
    #root
    #bin
    #daemon
    #adm
    #lp
    #sync
    #shutdown
    #halt
    #mail
    #news
    #uucp
    #operator
    #games
    #nobody
    am313

 

6, 新建一个虚拟用户的PAM文件。加上如下两行内容:

    

#vim /etc/pam.d/vsftpd-virtual
    auth required /lib/security/pam_userdb.so db=/etc/vsftpd/virtual-users
    account required /lib/security/pam_userdb.so db=/etc/vsftpd/virtual-users


    #如果使用的是64位系统,则要增加以下两句:

    auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/virtual-users
    account required /lib64/security/pam_userdb.so db=/etc/vsftpd/virtual-users

 

7, 创建一个chroot_list, 并置空即可

#touch /etc/vsftpd/chroot_list

8, 建立虚拟用户,设置该用户所要访问的目录,并设置虚拟用户访问的权限:

    chown -R :ftp /var/ftp
    chmod -R 775 /var/ftp  

         #chmod 700 /var/ftp/                 //默认应该这个目录且及应给予过权限

9, 重新启动VSFTP:

    #systemctl restart vsftpd


10, 在虚拟FTP服务器中,也可以对各个用户的权限进行设置。方法是在/etc/vsftpd.conf文件中添加如下一行:
    user_config_dir=用户配置文件目录

   然后在用户配置文件目录下创建相应的用户配置文件,比如为上述名为am313的用户创建一个配置文件(假设配置文件目录为/etc/vsftpd_user_conf):

    #vi /etc/vsftpd_user_conf/am313
    write_enable=NO
    anono_upload_enable=NO

11,虚拟用户个人目录设置

  大家可以发现,无论是哪个虚拟用户,登录后所在的目录都是/home/ftpsite,即都是guest用户的自家目录。下面,介绍如何为每个虚拟用户建立自家目录。
  一种作法是在虚拟用户的个人配置文件中使用local_root选项指定虚拟用户的自家目录。以am313为例,在第上步的基础上,首先/etc/vsftpd_user_conf/am313文件中加入:

    #vi /etc/vsftpd_user_conf/am313
    write_enable=YES
    anono_upload_enable=NO
    local_root=/var/ftp/pub/am313


12,添加FTP用户的步骤

   A.在account.txt中添加用户名和密码
   B.运行如下命令,将用户名和密码添加到数据库中    
    #db_load -T -t hash -f ./account.txt /etc/vsftpd/account.db
   C.在/home/ftpsite中新建一个文件夹,与用户明相同
   D.在vsftpd_user_conf文件夹下新建和用户名相同的文件,并在其中加入
    local_root=/home/ftpsite/用户名

 *常规错误集合:

A: 错误代码 530 Login incorrect

查看日志
tail -f /var/log/secure
发现PAM unable to dlopen(/lib/security/pam_userdb.so): /lib/security/pam_userdb.so: cannot open shared object file: No such file or directory
原来pam_userdb.so在/lib64/security/pam_userdb.so
解决方法,把/etc/pam.d/vsftpd文件中的/lib/security/去掉,改为
auth required pam_userdb.so db=/etc/vsftpd/vftpuser
account required pam_userdb.so db=/etc/vsftpd/vftpuser
或者
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vftpuser
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vftpuser

修改后重启vsftpd服务正常

B:错误代码 500 OOPS: vsftpd: refusing to run with writable root inside chroot () 

从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!
如果检查发现还有写权限,就会报该错误。
要修复这个错误,可以用命令chmod a-w /home/user去除用户主目录的写权限,注意把目录替换成你自己的。
或者你可以在vsftpd的配置文件中增加下列两项中的一项:
allow_writeable_chroot=YES

*常识:

在linux中添加ftp用户,并设置相应的权限,操作步骤如下:

1、环境:ftp为vsftp。被限制用户名为test。被限制路径为/home/test

2、建用户:在root用户下:

useradd -d /home/test test //增加用户test,并制定test用户的主目录为/home/test
passwd test //为test设置密码

3、更改用户相应的权限设置:

usermod -s /sbin/nologin test //限定用户test不能telnet,只能ftp
usermod -s /sbin/bash test //用户test恢复正常
usermod -d /test test //更改用户test的主目录为/test

4、限制用户只能访问/home/test,不能访问其他路径

修改/etc/vsftpd/vsftpd.conf如下:

chroot_list_enable=YES //限制访问自身目录
# (default follows)
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list

编辑 vsftpd.chroot_list文件,将受限制的用户添加进去,每个用户名一行

改完配置文件,不要忘记重启vsFTPd服务器
[root@linuxsir001 root]# /etc/init.d/vsftpd restart

5、如果需要允许用户修改密码,但是又没有telnet登录系统的权限:

usermod -s /usr/bin/passwd test //用户telnet后将直接进入改密界面

备用链接:

http://www.cnblogs.com/bienfantaisie/archive/2011/12/04/2275203.html

http://blog.haohtml.com/archives/9084

http://hx100.blog.51cto.com/44326/383143/  

http://www.cnblogs.com/hhuai/archive/2011/02/12/1952647.html 

 

转载于:https://my.oschina.net/am313/blog/737784

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值