目的
目的是首先在CentOS 7上配置基本的ProFTPD服务器。一旦设置了基本的FTP服务器,我们将添加FTP被动模式并通过添加传输层安全性(TLS)来提高安全性。
最后,我们添加了一个可选的匿名配置,以允许匿名用户无需用户名和密码即可登录FTP服务器。
操作系统和软件版本
- 操作系统:-CentOS Linux版本7.5.1804
- 软件:-ProFTPD版本1.3.5e
要求
以root或通过特权访问Ubuntu系统sudo
命令是必需的。
困难
介质
约定
使用说明
基本的FTP配置
让我们从ProFTP服务器的基本安装和配置开始。这包括安装,防火墙规则定义和客户端测试。
服务器设置
ProFTPD FTP服务器是EPEL存储库的一部分。因此,第一步是启用EPEL存储库,然后安装ProFTPD服务器:
# yum install epel-release
# yum install proftpd
接下来,启动ProFTPD服务器,并通过检查打开的端口来确认其正确启动21
# service proftpd start
# ss -nlt
接下来,我们需要将整个设备塞入服务器的防火墙中,以允许端口上的传入流量21
# firewall-cmd --add-port=21/tcp --permanent
# firewall-cmd --reload
确认打开的传入端口21
执行:
# firewall-cmd --list-ports
在此阶段,任何现有系统用户都可以通过FTP登录到新配置的ProFTPD服务器。我们可以选择创建一个新用户,例如lubos
可以访问目录/var/ftp-share
:
# useradd lubos -s /sbin/nologin -d /var/ftp-share
# passwd lubos
# chmod -R 750 /var/ftp-share
# setsebool -P allow_ftpd_full_access=1
客户端连接
此时,我们应该能够从远程客户端计算机执行FTP连接。最简单的测试是使用ftp
命令。
鉴于我们的ProFTPD服务器可以通过以下方式解决ftp.linuxconfig.org
主机名和用户lubos
存在执行:
$ ftp ftp.linuxconfig.org
Connected to ftp.linuxconfig.org.
220 FTP Server ready.
Name (ftp.linuxconfig.org:lubos): lubos
331 Password required for lubos
Password:
230 User lubos logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
被动模式FTP配置
服务器设置
要使我们的FTP服务器也接受被动FTP连接,请执行以下命令,以在IANA注册的临时端口范围上启用被动连接:
echo "PassivePorts 49152 65534" >> /etc/proftpd.conf
重新启动ProFTPD服务器:
# service proftpd restart
为范围内的端口开放防火墙49152-65534
:
# firewall-cmd --add-port=49152-65534/tcp --permanent
# firewall-cmd --reload
确认端口已正确打开:
# firewall-cmd --list-ports
FTP客户端连接
和以前一样,我们现在可以使用ftp
命令。确保这次您使用-p
选项如下所示:
$ ftp -p ftp.linuxconfig.org
Connected to ftp.linuxconfig.org.
220 FTP Server ready.
Name (ftp.linuxconfig.org:lubos): lubos
331 Password required for lubos
Password:
230 User lubos logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,1,111,209,252).
150 Opening ASCII mode data connection for file list
226 Transfer complete
ftp>
一切都按预期进行!
使用TLS保护FTP服务器
服务器设置
如果您打算在局域网之外使用FTP服务器,建议使用某种加密方式。幸运的是,使用TLS配置ProFTPD非常容易。首先,如果尚不可用,请安装openssl
包:
# yum install openssl
接下来,使用以下命令创建证书。唯一需要的值是Common Name
这是您的FTP服务器的主机名:
# openssl req -x509 -nodes -newkey rsa:1024 -keyout /etc/pki/tls/certs/proftpd.pem -out /etc/pki/tls/certs/proftpd.pem
Generating a 1024 bit RSA private key
...++++++
.......++++++
writing new private key to '/etc/pki/tls/certs/proftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:ftp.linuxconfig.org
Email Address []:
接下来,以root用户身份打开/etc/sysconfig/proftpd
使用您喜欢的文本编辑器并更改:
FROM:
PROFTPD_OPTIONS=""
TO:
PROFTPD_OPTIONS="-DTLS"
准备就绪后,重新启动ProFTPD服务器:
# service proftpd restart
客户端连接
这次我们使用FileZilla作为FTP测试客户端:
配置匿名FTP用户
服务器设置
要允许匿名用户登录到FTP服务器,请打开/etc/sysconfig/proftpd
使用您喜欢的文本编辑器并更改:
FROM:
PROFTPD_OPTIONS="-DTLS"
TO:
PROFTPD_OPTIONS="-DTLS -DANONYMOUS_FTP"
上面我们假设您先前已启用TLS。准备好后,重新启动FTP服务器:
# service proftpd restart
客户端连接
使用FileZilla作为我们的FTP测试客户端:
附录
阻止/拒绝用户的FTP访问
如果您需要阻止/拒绝任何系统用户的FTP服务器访问,请将其用户名添加到/etc/ftpusers
。每行一个用户名。这样任何用户尝试登录都会失败530
登录错误:
$ ftp ftp.linuxconfig.org
Connected to ftp.linuxconfig.org.
220 FTP Server ready.
Name (ftp.linuxconfig.org:lubos): lubos
331 Password required for lubos
Password:
530 Login incorrect.
Login failed.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>