CentOS7 架设 FTP 服务

大概操作流程

之前已经安装了 vsftpd 服务,并修改了配置

目前的状况是浏览器端可以登录,但无法显示文件列表

  1. 开机并启动 vsfptd
    # 启动服务
    service vsftpd start
    
    # 停止服务
    service vsftpd stop
    
    # 重启服务
    service vsftpd restart
    
    # 查看状态
    service vsftpd status
    
  2. Docker 中安装了 ftp 命令行工具,登录时提示错误 vsftpd: refusing to run with writable root inside chroot()
  3. 更改挂载目录的拥有者,仍然提示错误
  4. 挂载硬盘出错 mount /dev/sdb is write-protected mounting read-only mount: unknown filesystem type '(null)'
  5. 硬盘格式为 ntfs,格式化为linux支持的格式可以解决该问题,但硬盘中有数据,放弃了该方法
  6. 安装 ntfs-3g,使用该工具挂载硬盘
  7. 命令行登录ftp,提示错误 500 Illegal PORT command
  8. 将 vsftpd 设置为被动模式,增加 vsftpd 配置项
    # 开启被动模式
    pasv_enable=YES 
    
    # 被动模式最低端口
    pasv_min_port=30000 
    
    # 被动模式最高端口
    pasv_max_port=31000 
    
  9. 仍然看不到文件列表
  10. 下载 ftp 客户端,使用 filezilla 登录 ftp
  11. 发现将 ntfs 挂载之后目录权限均为 root,使用 chown 更改所属用户没有效果,后来通过 ntfs-3g 挂载时设置用户和用户组为 vsftpd 用户
  12. SELinux 在访问 ftp 时收到警告
  13. 设置 SELinux 对 ftp 的控制,允许访问目录
    # 查看 SELinux 中 ftp 权限
    getsebool -a | grep ftp
    
    # 允许 ftp 访问目录
    setsebool -P tftp_home_dir 1
    setsebool -P allow_ftpd_full_access 1
    
  14. 解决错误 vsftpd: refusing to run with writable root inside chroot(),在 vsftpd 配置文件中添加 allow_writeable_chroot=YES
  15. ftp 仍然无法显示挂载硬盘的目录列表,原因是设置 ftp 为被动模式,防火墙阻止了之前设置的用于传输数据的被动模式端口 30000-31000
  16. 批量开放防火墙端口
    firewall-cmd --permanent --zone=public --add-port=30000-31000/tcp
    firewall-cmd --reload
    
  17. 设置开机启动 vsftpd 服务 chkconfig vsftpd on
  18. 设置开机自动挂载 NTFS 硬盘
    # 编辑 /etc/fstab 文件
    UUID=831df52d-baad-4902-bcce-6128cec95411 /home/vsftpd/ftp ntfs-3g defaults 0 0
    

参考