如何在 Debian 8 上使用 TLS 安装和配置 vsftpd (Jessie)
本教程适用于这些操作系统版本
- Debian 6(挤压)
在此页
- 1 条初步说明
- 2 安装 vsftpd 和 OpenSSL
- 3 为 TLS 创建 SSL 证书
- 4 在 vsftpd 中启用 TLS
- 5 vsftpd 添加用户
- 6 为 TLS 配置 FileZilla
- 7 个链接
本文介绍如何在 Debian 8 服务器上设置启用 TLS 的 vsftpd 服务器,以及如何使用 FileZilla 访问 FTP 服务器。默认情况下,FTP 是一种非常不安全的协议,因为所有密码和所有数据都以明文形式传输。通过使用 TLS,可以对整个通信进行加密,从而使 FTP 更加安全。
1 初步说明
在本教程中,我将使用 IP 地址为 192.168.1.100 的主机名 server1.example.com。这些设置可能因您而异,因此您必须在适当的地方替换它们。我使用 Debian 8 最小服务器设置作为本教程的基础。
2 安装vsftpd和OpenSSL
TLS 需要 OpenSSL;要安装 vsftpd 和 OpenSSL,我们只需运行:
apt-get -y install vsftpd openssl
3 为 TLS 创建 SSL 证书
为了使用 TLS,我们必须创建一个 SSL 证书。我在 /etc/ssl/private 中创建它 - 如果该目录不存在,请立即创建它:
mkdir -p /etc/ssl/private
chmod 700 /etc/ssl/private
之后,我们可以生成 SSL 证书,如下所示:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem
国家名称(2 个字母代码)[AU]:<-- 输入您的国家名称(例如,\DE\)。
州或省名称(全名)[Some-State]:<-- 输入您的州或省名称。
地方名称(例如,城市)[]:<-- 输入您的城市。
组织名称(例如,公司)[Internet Widgits Pty Ltd]:<-- 输入您的组织名称(例如,您公司的名称)。
组织单位名称(例如,部门)[]:<-- 输入您的组织单位名称(例如 \IT 部门\)。
通用名称(例如,您的name) []:<-- 输入系统的完全限定域名(例如 \server1.example.com\)。
电子邮件地址 []:<-- 输入您的电子邮件地址。
4 在vsftpd中启用TLS
为了在 vsftpd 中启用 TLS,打开 /etc/vsftpd.conf...
nano /etc/vsftpd.conf
...并添加或更改以下选项:
[...]
# Turn on SSL
ssl_enable=YES
# Allow anonymous users to use secured SSL connections
allow_anon_ssl=YES
# All non-anonymous logins are forced to use a secure SSL connection in order to
# send and receive data on data connections.
force_local_data_ssl=YES
# All non-anonymous logins are forced to use a secure SSL connection in order to send the password.
force_local_logins_ssl=YES
# Permit TLS v1 protocol connections. TLS v1 connections are preferred
ssl_tlsv1=YES
# Permit SSL v2 protocol connections. TLS v1 connections are preferred
ssl_sslv2=NO
# permit SSL v3 protocol connections. TLS v1 connections are preferred
ssl_sslv3=NO
# Disable SSL session reuse (required by WinSCP)
require_ssl_reuse=NO
# Select which SSL ciphers vsftpd will allow for encrypted SSL connections (required by FileZilla)
ssl_ciphers=HIGH
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/private/vsftpd.pem
[...]
如果您使用 force_local_logins_ssl=YES 和 force_local_data_ssl=YES,则只允许 TLS 连接(这将锁定所有使用不支持 TLS 的旧 FTP 客户端的用户);通过使用 force_local_logins_ssl=NO 和 force_local_data_ssl=NO 允许 TLS 和非 TLS 连接,具体取决于 FTP 客户端支持的内容。
除了 TLS 选项之外,请确保您的 vsftpd.conf 中还具有以下设置以启用非匿名登录:
[...]
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
[...]
之后重启vsftpd:
service vsftpd restart
就是这样。您现在可以尝试使用您的 FTP 客户端进行连接;但是,您应该将 FTP 客户端配置为使用 TLS(如果您使用 force_local_logins_ssl=YES 和 force_local_data_ssl=YES,这是必须的)——请参阅下一章如何使用 FileZilla 执行此操作。
5 vsftpd 添加用户
在此步骤中,我们将添加一个可用于连接的本地 Linux 用户。我将使用密码 \howtoforge\ 创建一个用户 \till\。所有 FTP 用户都应在 mkdir /var/ftproot 中拥有他们的主目录,因此我将首先创建此目录。
mkdir /var/ftproot
然后使用命令添加用户:
adduser --home /var/ftproot/till till
adduser 命令将询问用户密码和其他一些详细信息
:/# adduser --home /var/ftproot/till till
Adding user `till' ...
Adding new group `till' (1001) ...
Adding new user `till' (1001) with group `till' ...
Creating home directory `/var/ftproot/till' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: <-- Enter the new password here
Retype new UNIX password: <-- Enter the new password here
passwd: password updated successfully
Changing the user information for till
Enter the new value, or press ENTER for the default
Full Name []: <-- Enter your name here or press enter to skip
Room Number []: <-- Enter room number here or press enter to skip
Work Phone []: <-- Enter work phone here or press enter to skip
Home Phone []: <-- Enter home phone here or press enter to skip
Other []: <-- Enter Other user details here or press enter to skip
Is the information correct? [Y/n] <-- Y
我们成功添加了一个 FTP 用户。
6 为 TLS 配置 FileZilla
为了使用带有 TLS 的 FTP,您需要一个支持 TLS 的 FTP 客户端,例如 FileZilla。
在 FileZilla 中,打开服务器管理器:

在服务器字段中输入 FTP 服务器的 IP 地址或主机名,选择协议“FTP”和“需要基于 TLS 的显式 FTP”,然后在用户字段中输入用户名。

现在您可以连接到服务器了。如果您是第一次这样做,您必须接受服务器的新 SSL 证书:

如果一切顺利,您现在应该已登录到服务器:

7个链接
- vsftpd:https://security.appspot.com/vsftpd.html
- FileZilla:http://filezilla-project.org/
- Debian:http://www.debian.org/