1. 安装 FTP 服务器

  1. $ sudo apt install vsftpd

2. 配置

编辑 vsftpd.conf

  1. sudo vi /etc/vsftpd.conf
  1. anonymous_enable=NO # line 25 不允许匿名用户登录
  2. local_enble=YES # line 28 允许本机登录
  3. write_enable=YES # line 31 允许上传文件到 FTP 服务器
  4. chroot _list_enable=Yes # line 123
  5. chroot_list_file=/etc/vsftpd.chroot_list # line 125 允许 vsftpd.chroot_list 文件中的用户登录 FTP 服务器
  6. local_root=/home/username/ftp # line 159 指定 ftp 上传下载目录

建立允许登录的用户文件

  1. $ sudo vi /etc/vsftpd.chroot_list # 将一个登录用户名放到此文件中, 放入在登录 FTP 服务器时使用的用户名

将 ~/username/ftp 文件夹的拥有者权限去掉 w (文件夹拥有者不能拥有写权限).
注意 ftp 文件夹的拥有者必须是用户, 即不能加 sudo 创建这个文件夹.

  1. $ sudo chmod -w ftp

在 ftp 文件夹中建立一个文件夹, 此文件夹就是使用 ftp 客户端进行下载, 上传的文件夹.

  1. $ cd ftp
  2. $ sudo mkdir share
  3. $ sudo chmod 777 share

3. 重启 FTP 服务

  1. $ sudo /etc/init.d/vsftpd restart

4. 登录

  1. 使用命令行
  1. $ ftp server-ip # 连接服务器
  2. $ put local-file remote-file # 上传文件
  3. $ get remote-file [ local-file ] # 下载文件
  1. 使用可视化客户端

使用 FileZilla3.