在 Debian 上配置 FTP 服务器使用证书(SSL/TLS),常见做法是使用 vsftpd + FTPS(显式/隐式 TLS)。下面以 vsftpd 为例,一步一步说明。
sudo apt update
sudo apt install vsftpd
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/ 需保护权限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
编辑配置文件:
sudo nano /etc/vsftpd.conf
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
云服务器还需在安全组开放这些端口。
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
| 类型 | 端口 | 说明 |
|---|---|---|
| 显式 FTPS | 21 | 推荐(FTPES) |
| 隐式 FTPS | 990 | 老系统 |
FileZilla 示例:
sudo tail -f /var/log/vsftpd.log
如果你用的是 ProFTPD / Pure-FTPd,或者想要 SFTP(SSH)而非 FTPS,可以告诉我,我给你对应配置。