zoukankan      html  css  js  c++  java
  • Linux:离线搭建vsftpd服务并记录新建用户登录报错问题

    1. 检查本机是否安装过vsftpd

    #检查是否存在vsftpd
    rpm -qa | grep vsftpd

    2. 下载离线安装包

    下载地址:http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)

    3. 开始安装vsftpd

    #安装vsftpd
    rpm -ivh vsftpd-3.0.2-21.el7.x86_64.rpm

    4. 测试是否安装成功

    #测试是否安装成功
    systemctl status vsftpd
    
    #启动ftp
    systemctl start vsftpd
    
    #关闭ftp
    systemctl stop vsftpd
    
    #开机自启ftp
    systemctl enable vsftpd

    #取消开机自启
    systemctl disable vsftpd

    5. 查看vsftpd涉及目录

    #查看vsftpd配置目录
    whereis vsftpd

    #配置文件vsftpd.conf在 /etc/vsftpd 目录中

    6. 修改配置文件vsftpd.conf

    #切换目录
    cd /etc/vsftpd/
    
    #备份配置文件
    cp vsftpd.conf vsftpd.conf.bak
    
    #修改配置文件
    vi vsftpd.conf
    #### 在配置文件的末尾追加如下配置
    
    pasv_enable=YES
    pasv_min_port=3000
    pasv_max_port=6000
    #配置ftp的根路径地址
    local_root=/home/ftp
    #将所有用户限制在ftp根目录下 yes/no chroot_local_user=YES anon_root=/home/ftp
    #从2.3.5版本后,vsftpd增强了安全检查,如果用户被限制在ftp主目录下,则该用户的主目录不能具备写权限,如果发现有写权限就会报错,或正确账户密码也登录失败
    #加上下面配置可以使xftp或原生ftp客户端均可正常访问
    allow_writeable_chroot=YES
    #提升ftp根路径权限
    cd /home
    
    mkdir ftp
    
    chmod 777 /home/ftp

    7. 禁用selinux

    #禁用selinux
    vi /etc/selinux/config
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled    ### 修改SELINUX为 disabled
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted 
    #查看状态
    getsebool -a | grep ftp
    
    #开启服务
    setsebool allow_ftpd_full_access on

    8. 配置防火墙规则

    /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
    
    /sbin/iptables -A INPUT -p tcp --dport 6000:7000 -j ACCEPT
    
    /etc/rc.d/init.d/iptables save
    
    /etc/init.d/iptables restart

    9. 创建ftp用户

    #创建用户
    useradd -s /bin/bash -d /home/ftp newUser
    
    #设置密码
    passwd newUser
    #输入密码:
    #再次输入密码:

    #重启vsftpd
    systemctl restart vsftpd

    10. 更改权限或删除ftp用户

    #更改用户权限
    usermod -s /sbin/nologin test    #限定用户test不能telnet,只能ftp
    usermod -s /bin/bash test    #用户test恢复正常
    usermod -d /home/test test      #更改用户test的主目录为/test
    
    #删除用户
    userdel -r newUser

    #查看所有用户
    cat /etc/passwd | grep ftp

    11. 新建用户登录报错 

    问题1:vsftpd新建 nologin 或 false 用户,账户密码正确但是登录一直报错问题

    #问题原因:
    vsftpd在登录验证的时候会检测 /sbin/nologin 或 /bin/false 是否在 /etc/shells 列表中,没有的话就会一直登录失败
    
    #解决方法:
    #修改/etc/shells文件
    vi /etc/shells
    
    #添加一行
    /sbin/nologin  #如果是nologin,添加这一行
    /bin/false    #如果是false,添加这一行

    问题2:vsftpd随意新建新用户,账户密码正确但是登录一直报错

    #问题原因:
    执行新建用户时的权限是root,所以目录所有者和所在组都是root,并且默认权限为700,导致新建用户没有权限登录ftp
    
    #解决方法:
    #查看ftp所有用户 (如果你清楚你的用户名,跳过这一步 ) 
    cat /etc/passwd | grep ftp
    #查看linux所有用户
    more /etc/group
    
    #查看用户所属的组
    gourps 用户名  #示例 gourps uftp
    
    #更改ftp根目录的所有者权限 ( -R 当前目录及所有其子目录 )
    chown -R 用户名 ftp根路径  #示例 chown -R uftp /home/ftp
    
    #更改ftp根目录的用户组权限 ( -R 当前目录及所有其子目录 )
    chgrp -R 组名 ftp根路径  #示例 chgrp -R uftp /home/ftp
    
    #可以通过chown同时更改用户和组
    chown -R 用户名.组名 ftp根路径  #示例 chown -R uftp.uftp /home/ftp

    文章整合至:https://blog.csdn.net/weixin_30381793/article/details/97074604https://blog.csdn.net/piaocoder/article/details/50719149https://www.cnblogs.com/zhjh256/p/9155281.html

    ----------------------------------- 作者:怒吼的萝卜 链接:http://www.cnblogs.com/nhdlb/ -----------------------------------
  • 相关阅读:
    Centos6.5下搭建nagios详解
    Centos6.5下升级Python版本
    Python生成随机密码
    配置apache使用https访问
    Irrlicht 论坛好贴 精选(不断补充中...)
    [原创]一个在Irrlicht中会常用的字符串转换函数
    [转]Scrolling Credits Code
    [原创]Irrlicht中的Texture透明色(colorkey)
    [原创]IrrLicht的GUI使用
    [转](C++) How to animate and move an entity
  • 原文地址:https://www.cnblogs.com/nhdlb/p/15082869.html
Copyright © 2011-2022 走看看