centos离线安装FTP服务器
时间: 2025-09-11 08:54:59 AIGC 浏览: 6
在 CentOS 系统中离线安装 FTP 服务器,主要涉及安装 `vsftpd` 服务并进行基本配置。以下是详细的步骤说明:
### 安装 vsftpd
1. 下载 `vsftpd` 的 RPM 包,例如 `vsftpd-2.2.2-11.el6.x86_64.rpm`。确保该 RPM 包适用于当前系统版本。
2. 使用 `rpm` 命令安装 `vsftpd`:
```bash
rpm -ivh vsftpd-2.2.2-11.el6.x86_64.rpm
```
### 启动 vsftpd 服务
1. 启动服务:
```bash
systemctl start vsftpd
```
2. 设置开机启动:
```bash
systemctl enable vsftpd
```
### 配置 vsftpd
1. 编辑主配置文件 `/etc/vsftpd/vsftpd.conf`:
- 禁用匿名用户登录:
```bash
anonymous_enable=NO
```
- 允许本地用户登录:
```bash
local_enable=YES
```
- 开启写权限:
```bash
write_enable=YES
```
- 设置用户登录后所在的目录(例如 `/usr/local/nginx/html/picture`):
```bash
local_root=/usr/local/nginx/html/picture
```
- 配置 chroot 环境:
```bash
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
```
确保 `/etc/vsftpd/chroot_list` 文件中列出的用户可以切换到其他目录,未列出的用户则被限制在其主目录中 [^4]。
2. 创建 `chroot_list` 文件(如果未存在):
```bash
touch /etc/vsftpd/chroot_list
```
添加允许切换目录的用户到该文件中。
3. 确保用户主目录的权限正确:
```bash
chown -R ftpuser /usr/local/nginx/html/picture
```
4. 修改 `/etc/shells` 文件以允许用户使用 `vsftpd`:
添加以下内容:
```bash
/sbin/nologin
```
### 配置防火墙
1. 开放 FTP 服务端口(默认为 21):
```bash
iptables -I INPUT -p tcp --dport 21 -j ACCEPT
```
2. 保存规则并重启防火墙:
```bash
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
```
3. 如果使用被动模式,还需要开放端口范围(例如 6000-7000):
```bash
iptables -I INPUT -p tcp --dport 6000:7000 -j ACCEPT
```
### 测试 FTP 服务
1. 使用 FTP 客户端连接测试:
```bash
ftp localhost
```
2. 输入用户名和密码验证登录。
### 常见问题解决
1. **无法读取 chroot 列表文件**:
- 确保 `/etc/vsftpd/chroot_list` 文件存在且路径正确。
- 检查文件权限,确保 `vsftpd` 可以读取该文件。
2. **被动模式连接失败**:
- 确认防火墙配置是否正确,允许指定的端口范围(如 6000-7000)。
3. **目录权限问题**:
- 确保目标目录的权限和所有权设置正确,例如 `/usr/local/nginx/html/picture` 的 owner 应为 `ftpuser` [^3]。
###
阅读全文
相关推荐


















