温馨提示×

debian ftpserver怎样配证书

小樊
47
2026-10-09 17:19:32
栏目: 智能运维

在 Debian 上配置 FTP 服务器使用证书(SSL/TLS),常见做法是使用 vsftpd + FTPS(显式/隐式 TLS)。下面以 vsftpd 为例,一步一步说明。


一、安装 vsftpd

sudo apt update
sudo apt install vsftpd

二、生成证书(自签或正式)

1️⃣ 自签名证书(测试用)

sudo openssl req -x509 -nodes -days 365 \
  -newkey rsa:2048 \
  -keyout /etc/ssl/private/vsftpd.key \
  -out //etc/ssl/certs/vsftpd.crt

⚠️ 注意:

  • /etc/ssl/private/ 需保护权限
  • 正式环境建议用 Let’s Encrypt

2️⃣ Let’s Encrypt(推荐生产)

sudo apt install certbot
sudo certbot certonly --standalone -d ftp.example.com

证书路径一般为:

/etc/letsencrypt/live/ftp.example.com/fullchain.pem
/etc/letsencrypt/live/ftp.example.com/privkey.pem

三、配置 vsftpd 使用证书

编辑配置文件:

sudo nano /etc/vsftpd.conf

基础 SSL 配置(显式 FTPS)

listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES

# SSL/TLS
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/ssl/certs/vsftpd.crt
rsa_private_key_file=/etc/ssl/private/vsftpd.key

# 被动模式(云服务器必须)
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=50000

使用 Let’s Encrypt 时改为:

rsa_cert_file=/etc/letsencrypt/live/ftp.example.com/fullchain.pem
rsa_private_key_file=/etc/letsencrypt/live/ftp.example.com/privkey.pem

四、防火墙设置

sudo ufw allow 21
sudo ufw allow 40000:50000/tcp

云服务器还需在安全组开放这些端口。


五、重启 vsftpd

sudo systemctl restart vsftpd
sudo systemctl enable vsftpd

六、客户端连接方式

类型 端口 说明
显式 FTPS 21 推荐(FTPES)
隐式 FTPS 990 老系统

FileZilla 示例:

  • 协议:FTP
  • 加密:需要显式 FTP over TLS
  • 端口:21

七、常见问题

❌ 证书不受信任

  • 自签证书需手动信任
  • 生产环境用 Let’s Encrypt

❌ 被动模式连不上

  • 检查 pasv 端口 & 防火墙

❌ 登录失败

sudo tail -f /var/log/vsftpd.log

如果你用的是 ProFTPD / Pure-FTPd,或者想要 SFTP(SSH)而非 FTPS,可以告诉我,我给你对应配置。

0 踩