下面以 Ubuntu + vsftpd 为例,介绍如何为 FTP 配置 SSL/TLS(FTPS),这是最常见、也是官方推荐的做法。
sudo apt update
sudo apt install vsftpd -y
sudo openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/ssl/private/vsftpd.key \
-out /etc/ssl/certs/vsftpd.crt
按提示填写信息即可,证书有效期 365 天
sudo apt install certbot -y
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
# 启用 SSL
ssl_enable=YES
# 禁止匿名用户使用 SSL
allow_anon_ssl=NO
# 强制本地用户使用 SSL
force_local_data_ssl=YES
force_local_logins_ssl=YES
# SSL 证书路径
rsa_cert_file=/etc/ssl/certs/vsftpd.crt
rsa_private_key_file=/etc/ssl/private/vsftpd.key
# 禁用 SSL v2/v3,使用 TLS
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
# 提高安全性
require_ssl_reuse=NO
ssl_ciphers=HIGH
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
pasv_address=你的服务器公网IP
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
sudo ufw allow 21/tcp
sudo ufw allow 30000:31000/tcp
sudo ufw reload
| 客户端 | 连接方式 |
|---|---|
| FileZilla | 协议选择 FTP over TLS |
| WinSCP | 协议选择 FTP + TLS/SSL |
| lftp | set ftp:ssl-force true |
⚠️ 不要使用 SFTP(SSH),那是完全不同的协议
/etc/shellspam 限制(必要时)如果你需要:
告诉我你的具体环境,我可以给你定制配置。