温馨提示×

CentOS如何开启FTPServer

小樊
39
2026-07-20 13:27:12
栏目: 智能运维

在 CentOS 上开启 FTPServer(FTP 服务),常见做法是使用 vsftpd(Very Secure FTP Daemon)。下面我按 CentOS 7 / 8 / Stream 通用方式给你一个完整流程,包含安装、配置、防火墙、SELinux、启动服务


一、安装 vsftpd

yum install -y vsftpd

CentOS 8 / Stream 可用 dnf install -y vsftpd


二、启动并设置开机自启

systemctl start vsftpd
systemctl enable vsftpd

查看状态:

systemctl status vsftpd

三、配置 FTP(核心)

配置文件路径:

/etc/vsftpd/vsftpd.conf

1️⃣ 备份原配置

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

2️⃣ 常用基础配置(推荐)

编辑:

vi /etc/vsftpd/vsftpd.conf

示例配置(允许本地用户登录):

# 禁止匿名登录
anonymous_enable=NO

# 允许本地用户
local_enable=YES

# 允许写操作
write_enable=YES

# 本地用户上传文件权限
local_umask=022

# 限制用户只能在自己家目录(重要)
chroot_local_user=YES

# 允许 chroot 目录可写(CentOS 7+ 必须)
allow_writeable_chroot=YES

# 监听 IPv4
listen=YES
listen_ipv6=NO

四、创建 FTP 用户(可选)

useradd ftpuser
passwd ftpuser

设置家目录(可选):

usermod -d /data/ftp ftpuser

五、防火墙放行 FTP 端口

FTP 默认使用 21 端口

firewalld

firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload

iptables(老系统)

iptables -I INPUT -p tcp --dport 21 -j ACCEPT
service iptables save

六、SELinux 设置(非常重要)

如果 SELinux 是 enforcing,FTP 很可能连不上。

查看状态

getenforce

允许 FTP 访问

setsebool -P ftp_home_dir on
setsebool -P allow_ftpd_full_access on

七、重启 vsftpd

systemctl restart vsftpd

八、测试 FTP

本机测试

ftp localhost

客户端工具

  • Windows:FileZilla
  • Linux:ftp / lftp

九、常见问题排查

❌ 530 Login incorrect

  • 用户名密码错误
  • /etc/shells 中缺少用户 shell
  • SELinux 没关或没配置

❌ 500 OOPS: vsftpd: refusing to run with writable root inside chroot()

allow_writeable_chroot=YES

❌ 连接超时

  • 防火墙没放行
  • 云服务器安全组没放行 21 端口

十、如果你指的是 FTPS(FTP over SSL)

如果你要的是 加密 FTP(FTPS,不是 SFTP),可以告诉我,我给你 SSL 证书 + vsftpd SSL 配置 的完整步骤。


总结一句话

CentOS 开启 FTP Server 最常用的是 vsftpd,改配置 → 放行端口 → 处理 SELinux → 启动服务。

如果你告诉我:

  • CentOS 具体版本
  • 是否需要 加密(FTPS)
  • 是否用于 公网 / 云服务器

我可以给你一份完全适配你环境的配置

0