Files
chill_notes/Linux/AliYun/阿里云使用FTP.md
2026-04-21 20:33:02 +08:00

151 lines
2.1 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 阿里云使用 FTP
> Ubuntu vsftpd 配置教程
---
## 安装 vsftpd
```bash
sudo apt-get update
sudo apt-get install vsftpd
```
---
## 配置 vsftpd
```bash
sudo vim /etc/vsftpd.conf
```
推荐配置:
```ini
# === 系统默认(保持不变)===
listen=NO
listen_ipv6=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
# === 自定义配置 ===
# 不允许匿名访问
anonymous_enable=NO
# 允许本地用户访问
local_enable=YES
# 开启写模式
write_enable=YES
# 新建文件权限 (777-022=755)
local_umask=022
# 使用 user_list 白名单
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd.user_list
# 限制用户切换目录
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
allow_writeable_chroot=YES
# FTP 根目录
local_root=/var/myftp
```
---
## 重启服务
```bash
sudo systemctl restart vsftpd
```
---
## 创建 FTP 用户
```bash
# 创建用户并指定家目录
sudo useradd -d /var/myftp ftpuser
# 设置密码
sudo passwd ftpuser
# 创建白名单文件
sudo vim /etc/vsftpd.user_list
# 添加ftpuser
# 创建黑名单文件(可为空)
sudo vim /etc/vsftpd.chroot_list
```
---
## 设置目录权限
```bash
# 创建目录
sudo mkdir -p /var/myftp/{upload,download}
# 设置权限
sudo chmod 555 /var/myftp # 根目录只读
sudo chmod 755 /var/myftp/upload # 上传目录可写
sudo chmod 555 /var/myftp/download # 下载目录只读
# 修改所有者
sudo chown -R ftpuser:ftpuser /var/myftp
```
---
## 常见问题
### 530 Login incorrect
```bash
sudo vim /etc/pam.d/vsftpd
# 注释掉这行:
# auth required pam_shells.so
```
### 550 Permission denied
```bash
# 关闭 SELinux
setsebool -P ftpd_disable_trans on
sudo systemctl restart vsftpd
```
### 被动模式问题
登录后执行:
```
passive
```
---
## 客户端连接
```bash
ftp 服务器IP
# 输入用户名和密码
```
---
## 常用 FTP 客户端
- **Windows**FileZilla、WinSCP
- **macOS/Linux**FileZilla、Cyberduck
---
> 参考:[vsftpd 配置详解](https://www.cnblogs.com/dupengcheng/p/6790143.html)