debian

Debian FTP服务器SSL证书安装指南

小樊
46
2025-09-24 21:30:38
栏目: 云计算

Debian FTP Server SSL Certificate Installation Guide

This guide provides step-by-step instructions to secure your Debian FTP server with SSL/TLS encryption using vsftpd (a widely used FTP daemon) and either a self-signed certificate (for testing) or a trusted certificate from Let’s Encrypt (for production).

Prerequisites

Step 1: Install vsftpd

Update your package list and install vsftpd:

sudo apt update && sudo apt install vsftpd -y

After installation, start and enable the service to ensure it boots automatically:

sudo systemctl start vsftpd && sudo systemctl enable vsftpd

Step 2: Obtain an SSL Certificate

You have two options for SSL certificates: self-signed (free, for testing) or trusted (from Let’s Encrypt, for production).

Option A: Generate a Self-Signed Certificate (Testing Only)

Run the following command to create a 365-day self-signed certificate:

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

Option B: Use Let’s Encrypt (Trusted Certificate, Production)

Install certbot and the FTP plugin to simplify certificate issuance:

sudo apt install certbot python3-certbot-ftp -y

Request a certificate for your domain (replace yourdomain.com with your actual domain):

sudo certbot --ftp -d yourdomain.com

Follow the on-screen instructions (you’ll need to verify domain ownership via email or HTTP). Certbot will automatically place the certificate in /etc/letsencrypt/live/yourdomain.com/ (with symlinks to fullchain.pem and privkey.pem).

Step 3: Configure vsftpd for SSL

Edit the vsftpd configuration file to enable SSL and specify certificate paths:

sudo nano /etc/vsftpd.conf

Modify or add the following lines (adjust paths based on your certificate type):

Setting Purpose Example Value
ssl_enable=YES Enables SSL/TLS encryption for the FTP server. YES
rsa_cert_file Path to the SSL certificate file. /etc/ssl/certs/vsftpd.pem (self-signed) or /etc/letsencrypt/live/yourdomain.com/fullchain.pem (Let’s Encrypt)
rsa_private_key_file Path to the SSL private key file. /etc/ssl/private/vsftpd.pem (self-signed) or /etc/letsencrypt/live/yourdomain.com/privkey.pem (Let’s Encrypt)
force_local_data_ssl=YES Forces data connections (file transfers) to use SSL. YES
force_local_logins_ssl=YES Forces login authentication to use SSL. YES
ssl_tlsv1=YES Enables TLSv1 protocol (recommended for compatibility). YES
ssl_sslv2=NO Disables SSLv2 (insecure, deprecated). NO
ssl_sslv3=NO Disables SSLv3 (insecure, deprecated). NO
allow_anon_ssl=NO Disables SSL for anonymous users (recommended for security). NO

Save the file and exit (Ctrl+O, Enter, Ctrl+X).

Step 4: Restart vsftpd and Verify Configuration

Apply the changes by restarting the vsftpd service:

sudo systemctl restart vsftpd

Check the service status to ensure it’s running without errors:

sudo systemctl status vsftpd

You should see “active (running)” in the output.

Step 5: Configure the Firewall

Allow FTP (port 21) and FTPS (port 990) traffic through the firewall (using ufw as an example):

sudo ufw allow 21/tcp      # Standard FTP port (for passive mode fallback)
sudo ufw allow 990/tcp     # FTPS control port (explicit TLS)
sudo ufw allow 40000:50000/tcp  # Passive mode data ports (adjust range as needed)
sudo ufw reload

Step 6: Test the SSL Connection

Use an FTP client like FileZilla to verify the setup:

  1. Open FileZilla and go to File > Site Manager.
  2. Click New Site, enter your server’s domain/IP, and select FTP - File Transfer Protocol.
  3. Set the Encryption dropdown to Require explicit FTP over TLS.
  4. Enter your FTP username and password, then click Connect.

If the connection succeeds, you’ll see a padlock icon next to the server name in the FileZilla toolbar, indicating an encrypted SSL session.

Notes & Best Practices

By following these steps, you’ll secure your Debian FTP server with SSL/TLS, protecting data in transit from eavesdropping and tampering.

0
看了该问题的人还看了