在 Ubuntu 上搭建 FTP 服务器并启用 SSL(通常是 FTPS),最常用的是 vsftpd。下面以 vsftpd + SSL/TLS 为例说明完整步骤。
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
按提示填写国家、组织等信息即可
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
# 启用 SSL
ssl_enable=YES
# 证书和私钥
rsa_cert_file=/etc/ssl/certs/vsftpd.crt
rsa_private_key_file=/etc/ssl/private/vsftpd.key
# 强制使用 TLS(推荐)
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
# 允许匿名和用户使用 SSL
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
# 被动模式(云服务器必须)
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
如果是 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 systemctl restart vsftpd
sudo systemctl enable vsftpd
sudo ufw allow 21
sudo ufw allow 30000:31000/tcp
云服务器还需在安全组放行 21 和 30000–31000
常用客户端:
连接类型选择:
FTP over TLS (FTPS)
openssl s_client -connect localhost:21 -starttls ftp
看到证书信息即说明成功。
如果你用的是 ProFTPD / Pure-FTPd,或者需要 隐式 FTPS / 只允HTTPS管理,可以告诉我,我可以给你对应配置。