CentOS从零开始如何部署FTP服务器

941
2025/2/14 15:31:44
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS上从零开始部署FTP服务器,可以按照以下步骤进行:

1. 更新系统

首先,确保你的CentOS系统是最新的。

sudo yum update -y

2. 安装FTP服务器软件

CentOS默认不安装FTP服务器,但你可以使用vsftpd(Very Secure FTP Daemon)作为FTP服务器。安装它:

sudo yum install vsftpd -y

3. 配置vsftpd

编辑vsftpd的配置文件:

sudo vi /etc/vsftpd/vsftpd.conf

根据你的需求进行配置。以下是一些常用的配置选项:

  • listen=YES:启用监听模式。
  • listen_ipv6=NO:禁用IPv6监听。
  • anonymous_enable=NO:禁止匿名用户登录。
  • local_enable=YES:允许本地用户登录。
  • write_enable=YES:允许FTP写操作。
  • chroot_local_user=YES:将本地用户锁定在其主目录中。
  • allow_writeable_chroot=YES:允许chroot目录可写。

4. 启动和启用vsftpd服务

启动vsftpd服务并设置开机自启:

sudo systemctl start vsftpd
sudo systemctl enable vsftpd

5. 配置防火墙

确保防火墙允许FTP流量。你可以使用firewalld来配置:

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

6. 创建FTP用户

创建一个用于FTP访问的用户,并设置密码:

sudo adduser ftpuser
sudo passwd ftpuser

7. 测试FTP连接

使用FTP客户端(如FileZilla)连接到你的服务器,地址为your_server_ip,用户名为ftpuser,密码为你设置的密码。

8. 安全加固(可选)

为了提高安全性,你可以考虑以下措施:

  • 使用SSL/TLS加密FTP连接。
  • 配置SELinux策略以限制FTP访问。
  • 定期更新系统和软件包。

使用SSL/TLS加密FTP连接

  1. 安装vsftpd的SSL模块:

    sudo yum install vsftpd-ssl -y
    
  2. 生成SSL证书和密钥:

    sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/vsftpd.pem -out /etc/pki/tls/certs/vsftpd.pem
    
  3. 编辑vsftpd配置文件以启用SSL:

    sudo vi /etc/vsftpd/vsftpd.conf
    

    添加或修改以下行:

    ssl_enable=YES
    allow_anon_ssl=NO
    force_local_data_ssl=YES
    force_local_logins_ssl=YES
    ssl_tlsv1=YES
    ssl_sslv2=NO
    ssl_sslv3=NO
    rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem
    rsa_private_key_file=/etc/pki/tls/private/vsftpd.pem
    
  4. 重启vsftpd服务:

    sudo systemctl restart vsftpd
    

通过以上步骤,你应该能够在CentOS上成功部署一个FTP服务器。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: centos sqladmin使用有哪些技巧