zoukankan      html  css  js  c++  java
  • CentOS 7搭建vsftp服务

    CentOS 7搭建vsftp服务

    1. 安装前准备

    • 关闭防火墙或者开端口权限。一般是firewalld或者iptables。
    systemctl stop firewalld
    systemctl disable firewalld
    
    • 关闭sellinux

    临时关闭

    setenforce 0
    

    重启机器关闭

    vi /etc/selinux/config
    修改
    SELINUX=disabled
    

    查看是否关闭

    getenforce
    

    2. 安装vsftpd

    yum install -y vsftpd ftp
    systemctl start vsftpd
    systemctl enable vsftpd
    

    3. 配置vsftpd

    • 创建vsftpd使用的系统用户,主目录为/home/vsftpd,禁止ssh登录。创建之后所有虚拟用户使用这个系统用户访问文件。
    useradd vsftpd -d /home/vsftpd -s /bin/false
    
    • 创建虚拟用户主目录,比如虚拟用户叫ftp1,执行下面的命令。
    mkdir -p /home/vsftpd/ftp1
    chmod 755 /home/vsftpd/ftp1
    chown vsftpd.vsftpd /home/vsftpd/ftp1
    
    • 创建这个虚拟用户
    vi /etc/vsftpd/loginusers.conf
    增加
    ftp1
    123456
    

    这样就创建了ftp1这个虚拟用户,密码为123456

    • 根据这个文件创建数据库文件
    db_load -T -t hash -f /etc/vsftpd/loginusers.conf /etc/vsftpd/loginusers.db
    chmod 600 /etc/vsftpd/loginusers.db
    
    • 启用这个数据库文件
    vi /etc/pam.d/vsftpd
    注释掉所有内容后,增加下面的内容
    
    auth    sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers
    account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/loginusers
    
    • 创建虚拟用户配置文件
    mkdir /etc/vsftpd/userconf
    vi /etc/vsftpd/userconf/ftp1    # 这里的文件名称必须与虚拟用户名一致
    增加下面的内容
    # 设置登录后禁锢的目录
    local_root=/home/vsftpd/ftp1/
    # 开放写权限
    write_enable=YES
    # 开放下载权限
    anon_world_readable_only=no
    # 开放上传权限
    anon_upload_enable=yes
    # 开放创建目录的权限
    #anon_mkdir_write_enable=yes
    # 开放删除和重命名的权限
    anon_other_write_enable=yes
    
    • 最后修改主配置文件
    vi /etc/vsftpd/vsftpd.conf
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    dirmessage_enable=YES
    xferlog_enable=YES
    connect_from_port_20=YES
    xferlog_std_format=YES
    ascii_upload_enable=YES
    ascii_download_enable=YES
    chroot_local_user=YES
    listen=YES
    listen_ipv6=NO
    pam_service_name=vsftpd
    userlist_enable=YES
    tcp_wrappers=YES
    guest_enable=YES
    guest_username=vsftpd
    user_config_dir=/etc/vsftpd/userconf
    allow_writeable_chroot=YES
    
    # 以下是跟被动模式相关配置:
    pasv_enable=yes # 被动模式启动
    pasv_max_port=10250 # 启动的最大端口
    pasv_min_port=10240 # 启动的最小端口
    # 端口设置需要防火墙开启、华为云需要配置安全组
    pasv_address=114.1*6.*1.*7 # 华为云主机的IP,改为你自己的运服务器IP
    pasv_addr_resolve=yes # 配合pasv_address开启允许欺骗
    

    配置介绍:

      • anonymous_enable=NO 禁止匿名用户登录
      • chroot_local_user=YES 禁止用户访问除主目录以外的目录
      • ascii_upload_enable=YES ascii_download_enable=YES 设定支持ASCII模式的上传和下载功能
      • guest_enable=YES 启动虚拟用户
      • guest_username=vsftpd 虚拟用户使用的系统用户名
      • user_config_dir=/etc/vsftpd/userconf 虚拟用户使用的配置文件目录
      • allow_writeable_chroot=YES 最新版的vsftpd为了安全必须用户主目录(也就是/home/vsftpd/ftp1)没有写权限,才能登录,或者使用
      • allow_writeable_chroot=YES
    • 最后重启服务使配置生效

    systemctl restart vsftpd
    

    4. 登录测试

    • shell 查看
    # sudo su - vsftpd
    # pwd
    /home/vsftpd/ftp1
    # ls
    111.pdf
    

    5. 参考文档

    # 华为云Centos 7.4安装、配置FTP服务器vsftpd
    https://blog.csdn.net/qiantanlong/article/details/82909865
    
    # centos7安装vsftp配置虚拟用户,详细介绍,亲测完美!
    https://blog.csdn.net/will0532/article/details/79175478
    
    # CentOS 7搭建vsftp(虚拟用户方式登录)
    http://www.cnblogs.com/wsjhk/p/8311037.html
    
    
  • 相关阅读:
    ubuntu下 apt-get install 下载的文件存放的目录
    ubuntu 上更新安装 openoffice.org3的过程
    ubuntu中flash的中文乱码解决方法
    ubuntu 安装AMP环境的笔记 Prefork方式与fast-cgi方法
    socket 基础知识
    php 处理透明背景的图片时的问题
    RHEL 8 Speculation
    心之力
    (OK) 在内核中,获得 某目的地址的下一跳的数目,kernel 4.4
    Linux内核分析
  • 原文地址:https://www.cnblogs.com/xiaoqshuo/p/10416611.html
Copyright © 2011-2022 走看看