配置Linux FTP服务器以使用SSL加密可以确保数据传输的安全性。以下是使用vsftpd(Very Secure FTP Daemon)作为FTP服务器的示例步骤:
首先,确保你的系统已经安装了vsftpd和SSL证书。
在Debian/Ubuntu系统上:
sudo apt update
sudo apt install vsftpd
在CentOS/RHEL系统上:
sudo yum install vsftpd
你可以从Let’s Encrypt免费获取SSL证书,或者使用其他证书颁发机构。
使用Certbot获取Let’s Encrypt证书:
sudo apt install certbot python3-certbot-nginx # Debian/Ubuntu
sudo yum install certbot python3-certbot-nginx # CentOS/RHEL
sudo certbot --nginx -d yourdomain.com
编辑vsftpd配置文件 /etc/vsftpd.conf:
sudo nano /etc/vsftpd.conf
添加或修改以下配置项:
# 启用SSL
ssl_enable=YES
# 强制使用SSL
force_local_data_ssl=YES
force_local_logins_ssl=YES
# SSL证书和密钥文件路径
rsa_cert_file=/etc/letsencrypt/live/yourdomain.com/fullchain.pem
rsa_private_key_file=/etc/letsencrypt/live/yourdomain.com/privkey.pem
# 允许匿名用户使用SSL
allow_anon_ssl=NO
# 允许本地用户使用SSL
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
保存并退出编辑器。
重启vsftpd服务以应用更改:
在Debian/Ubuntu系统上:
sudo systemctl restart vsftpd
在CentOS/RHEL系统上:
sudo systemctl restart vsftpd
确保防火墙允许FTP和SSL流量。
在Debian/Ubuntu系统上使用ufw:
sudo ufw allow 21/tcp
sudo ufw allow 990/tcp # FTPS控制端口
sudo ufw allow 40000:50000/tcp # 被动模式端口范围
sudo ufw reload
在CentOS/RHEL系统上使用firewalld:
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=990/tcp
sudo firewall-cmd --permanent --add-port=40000-50000/tcp
sudo firewall-cmd --reload
使用FTP客户端连接到你的服务器,并验证是否使用了SSL加密。例如,使用命令行FTP客户端:
ftp -v yourdomain.com
你应该看到类似以下的输出,表明连接已加密:
Connected to yourdomain.com.
220 (vsFTPd 3.0.3)
User (yourdomain.com:yourusername) @ localhost ... logged in
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 user user 4096 Mar 1 12:34 file1.txt
-rw-r--r-- 1 user user 1234 Mar 1 12:34 file2.txt
226 Directory send OK.
ftp> quit
通过以上步骤,你已经成功配置了Linux FTP服务器以使用SSL加密。