This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 搭建 JCI FTP 服务小记 ====== > 注:本处的步骤仅供参考,请根据实际需求改动。操作环境为 Debian 9 x86_64。 ===== 服务需求 ===== * HTTP(S) 在线访问服务,但某些目录需要认证。 * (S)FTP 上传,但不能让用户访问/修改系统并执行系统命令。 ===== 步骤 ===== ==== 安装必备组件 ==== <code> $ sudo apt install nginx-extras apache2-utils </code> ==== 创建用户并给予权限 ==== === 创建用户 === <code> $ sudo groupadd ftp $ sudo useradd -g ftp ftpuser $ sudo usermod -s /sbin/nologin -d /home/ftp -m ftpuser $ sudo passwd ftpuser </code> === 设置登录 === 首先在 ''%%/etc/ssh/sshd_config%%'' 找到这段: <code> Subsystem sftp /usr/lib/openssh/sftp-server </code> 将其注释然后添加这一行: <code> Subsystem sftp internal-sftp </code> 然后在末尾添加: <code> Match Group ftp PasswordAuthentication yes ChrootDirectory /home/ftp X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp </code> === 文件权限 === 必须要给母目录 root 用户和组的权限,且设置为 755。但下面的目录可随意指定。 <code> $ sudo chown root:root /home/ftp $ sudo chmod 755 /home/ftp $ sudo chown ftpuser:ftp /home/ftp/files </code> ==== 设置网页服务器 ==== > 本处只展示需求的设置。 === 列出目录 === <code> location / { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; charset utf-8,gbk; try_files $uri $uri/ =404; } </code> === 认证目录 === <code> location /secret { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; charset utf-8,gbk; auth_basic "Enter your name and password"; auth_basic_user_file /var/www/ftp/.htpasswd; } </code> 然后设置用户名密码,这里假设用户名为 user: <code> $ sudo htpasswd -c /var/www/ftp/.htpasswd user </code>