• 沒有找到結果。

8.4.1 FTP 概述

FTP 是 TCP/IP 协议组中的协议之一,是 File Transfer Protocol 的缩写。在 Internet 中,大 部分的文件传送采用 FTP 协议。FTP 采用“客户机/服务器”的架构,FTP 服务器能在网络上 提供文件传输服务,可以供客户端上的用户上传和下载文件;用户需要在本地计算机上安装 FTP 客户端程序。FTP 可以提供跨平台的数据交换,如安装 Linux 和 Windows 操作系统的计 算机之间。

FTP 与其他通信协议最大的不同是,它使用两个连接端口来和客户端连接:TCP 20 和 TCP 21。其中,连接端口 TCP 20 用来传递数据,而 TCP 21 用来负责传输流程的控制。这种设计 可以支持多个客户端同时连接 FTP 服务器,并且具有稳定的优点。

一般来说,用户在访问 FTP 服务器的资源前需要先经过认证,FTP 服务器会要求用户输 入用户名及密码。如果管理员允许匿名进入,用户需要输入“anonymous”作为用户名,而密 码则不进行验证。

目前在 Linux 中常用的免费 FTP 服务器软件主要是 Wu-FTP、ProFTP、VSFTP 三种。其 中,Wu-FTP 使用最广泛。在 Red Hat Linux 7.2 中,Wu-FTP 是默认的 FTP 服务器软件。Red Hat Linux 8.0 中同时自带 Wu-FTP 和 VSFTP。可能由于 Wu-FTP 被发现安全漏洞比较多的原因,

到了 Red Hat Linux 9,只有 VSFTP 了。VSFTP 是 Very Secure FTP 的缩写,意思是“非常安 全的 FTP”。如果需要使用 Wu-FTP 或 ProFTP,用户也可以自己安装,配置的方法和 VSFTP 接近。

8.4.2 VSFTP 服务器的安装

Red Hat Linux 9 提供的 FTP 服务器软件为 vsftpd-1.1.3-8.i386.rpm。建立 FTP 服务器需要 首先安装该软件,可以使用以下命令检查该软件是否已经安装。

[root@rh9 root]# rpm -qa |grep vsftp

vsftpd-1.1.3-8 //该软件包已经安装。

由于 Red Hat Linux 9 自带 VSFTP 服务器软件,通常不需要另行安装。如果在安装系统时 没有安装,可以在图形界面的“主菜单”中选择“系统设置”→“添加删除应用程序”选项,

在出现的“软件包管理”对话框里面选中“FTP 服务器”选项,然后单击“更新”按钮,安装 屏幕提示插入第 2 张安装光盘即可开始安装。用户也可以用 rpm 命令来安装。

[root@rh9 dhcp]# mount /mnt/cdrom

[root@rh9 dhcp]# cd /mnt/cdrom/Red Hat/RPMS [root@rh9 root]# rpm -ivh vsftpd-1.1.3-8.i386.rpm 8.4.3 VSFTP 服务器的配置文件

VSFTP 的配置文件 主要 有 3 个, 分别是 /etc/vsftpd/vsftpd.conf 和 /etc/vsftpd.ftpuser 、 /etc/vsftpd.user_list。这些文件中的每一行都表示单一的注释或指令,如果以“#”开头表示该 行是注释行,同时会被服务器忽略。除注释以外的都属于指令,采用“选项=设置值”的格式,

每条指令都有一个默认值,可以在配置 VSFTP 服务器的时候根据具体的用户需要进行修改。

但要注意的是,只有重启 VSFTP 服务器进程(vsftpd)后,修改后的配置才会生效。

1./etc/vsftpd/vsftpd.conf

该文件是 VSFTP 最主要的配置文件,需要对它进行配置以发挥 VSFTP 服务器的最大功 能与安全性,该文件的默认内容及说明如下。

[root@rh9 root]# more /etc/vsftpd.conf

# Example config file /etc/vsftpd.conf

#

# The default compiled in settings are very paranoid. This sample file

# loosens things up a bit, to make the ftp daemon more usable.

#

# Allow anonymous FTP?

anonymous_enable=YES

#

# 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

#

# Uncomment this to allow the anonymous FTP user to upload files. This only

# has an effect if the above global write enable is activated. Also, you will

# obviously need to create a directory writable by the FTP user.

#anon_upload_enable=YES

#

# Uncomment this if you want the anonymous FTP user to be able to create

# new directories.

#anon_mkdir_write_enable=YES

#

# Activate directory messages - messages given to remote users when they

# go into a certain directory.

dirmessage_enable=YES

#

# Activate logging of uploads/downloads.

xferlog_enable=YES

#

# Make sure PORT transfer connections originate from port 20 (ftp-data).

connect_from_port_20=YES

#

# If you want, you can arrange for uploaded anonymous files to be owned by

# a different user. Note! Using "root" for uploaded files is not

# recommended!

#chown_uploads=YES

#chown_username=whoever

#

# You may override where the log file goes if you like. The default is shown

# below.

#xferlog_file=/var/log/vsftpd.log

#

# If you want, you can have your log file in standard ftpd xferlog format xferlog_std_format=YES

#

# You may change the default value for timing out an idle session.

#idle_session_timeout=600

#

# You may change the default value for timing out a data connection.

#data_connection_timeout=120

#

# It is recommended that you define on your system a unique user which the

# ftp server can use as a totally isolated and unprivileged user.

#nopriv_user=ftpsecure

#

# Enable this and the server will recognise asynchronous ABOR requests. Not

# recommended for security (the code is non-trivial). Not enabling it,

# however, may confuse older FTP clients.

#async_abor_enable=YES

#

# By default the server will pretend to allow ASCII mode but in fact ignore

# the request. Turn on the below options to have the server actually do ASCII

# mangling on files when in ASCII mode.

# Beware that turning on ascii_download_enable enables malicious remote parties

# to consume your I/O resources, by issuing the command "SIZE /big/file" in

# ASCII mode.

# These ASCII options are split into upload and download because you may wish

# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),

# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be

# on the client anyway..

#ascii_upload_enable=YES

#ascii_download_enable=YES

#

# You may fully customise the login banner string:

#ftpd_banner=Welcome to blah FTP service.

#

# You may specify a file of disallowed anonymous e-mail addresses. Apparently

# useful for combatting certain DoS attacks.

#deny_email_enable=YES

# (default follows)

#banned_email_file=/etc/vsftpd.banned_emails

#

# You may specify an explicit list of local users to chroot() to their home

# directory. If chroot_local_user is YES, then this list becomes a list of

# users to NOT chroot().

#chroot_list_enable=YES

# (default follows)

#chroot_list_file=/etc/vsftpd.chroot_list

#

# You may activate the "-R" option to the builtin ls. This is disabled by

# default to avoid remote users being able to cause excessive I/O on large

# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume

# the presence of the "-R" option, so there is a strong case for enabling it.

#ls_recurse_enable=YES pam_service_name=vsftpd userlist_enable=YES

#enable for standalone mode listen=YES

tcp_wrappers=YES

下面对该文件中的一些主要配置项进行说明。

(1)anonymous_enable=YES

是否允许匿名登录 FTP(YES/NO)服务器,默认值是 YES。

(2)local_enable=YES

若启用该功能,则允许本机使用者登录,默认值是 YES。

(3)write_enable=YES

是否允许客户端使用修改 FTP 服务器文件系统的 FTP 指令,如 MKD、DELE 等。默认值 是 YES,但从安全控制的角度建议设置为 NO。

(4)local_umask=022

本机登录者新增文档时的 umask 数值。umask 是通过八进制的数值来定义用户创建文件或 目录的默认权限,umask 表示的是禁止权限,其默认值为 077,这里设置为 022(大多 ftpd 都 设置为 022)。

(5)anon_upload_enable=YES

取值为 YES/NO。设置是否允许匿名用户上传文档的权限。需要先为 FTP 用户创建一个 可写的目录。

(6)anon_mkdir_write_enable=YES

取值为 YES/NO。设置是否允许匿名用户拥有创建新目录的权限。一般不建议开放该权限。

(7)dirmessage_enable=YES

取值为 YES/NO。如果启用该选项,当远程用户访问一个指定的目录时,系统将检查该目 录下是否有.message 文件。如果有,显示该文件内容。通常这个文件放置欢迎词或该项目录的 说明。

(8)connect_from_port_20=YES

取值为 YES/NO。若为 YES,表示所有 FTP 传递的数据(不是 FTP 的控制信息)都会通 过 20 号端口来进行。默认会使用该选项。

(9)chown_uploads=YES

取值为 YES/NO。若设置为 YES,所有匿名上传数据的所有者被更换为 chown_username 中设定的用户。这样的设置对于 FTP 的安全及管理很有用。

(10)chown_username=whoever

定义匿名登录者上传文档时,这些文档的所有者将被置换成的用户名称。

(11)xferlog_file=/var/log/vsftpd.log 定义日志文件(log file)的存放位置。

(12)xferlog_std_format=YES

将日志文件定义为标准 ftpd xferlog 的格式。

(13)idle_session_timeout=600

空闲时间超时设定,单位为秒。如果超出该时间还没有数据传送或指令输入,则连接中断。

(14)data_connection_timeout=120 数据连接的超时设定,单位为秒。

(15)nopriv_user=ftpsecure

定义运行 vsftd 进程的独立而非特权的系统用户。

(16)async_abor_enable=YES

取值为 YES/NO。若设置为 YES,FTP 服务器将认可异步 ABOR 请求。一般不推荐。

(17)ascii_upload_enable=YES

取值为 YES/NO。控制是否可用 ASCII 模式上传。

(18)ascii_download_enable=YES

取值为 YES/NO。控制是否可用 ASCII 模式下载。

(19)ftpd_banner=Welcome to blah FTP service.

定制登录欢迎词。

(20)deny_email_enable=YES

若启动该项功能,可以指定一个文件/etc/vsftpd.banner_email,其中包含电子邮件地址列表。

若用户用匿名登录,系统将要求输入邮件地址;如果输入的邮件地址在该项文档中,则不允许 链接。该项功能主要用于防范 DoS 攻击。

(21)banned_email_file=/etc/vsftpd.banned_emails 设置文件 vsftpd.banned_emails 的存放位置。

(22)chroot_list_enable=YES

取值为 YES/NO。如果启动该项功能,所有本机使用者登录均可进到根目录之外的目录,

列在/etc/vsftpd.chroot_list 中的使用者除外。

(23)chroot_list_file=/etc/vsftpd.chroot_list 设置文件 vsftpd.chroot_list 的存放位置。

(24)ls_recurse_enable=YES

取值为 YES/NO。若启动该项功能,允许登录用户使用 ls_R 指令。

(25)pam_service_name=vsftpd 定义 PAM 使用的名称。

(26)userlist_enable=YES

取值为 YES/NO。如果设置为“YES”,则/etc/vsftpd.user_list 文件会生效。

(27)userlist_deny=YES

取值为 YES/NO。该项只有在 userlist_enable 启动时才有效。如果将该选项设置为 YES,

则在/etc/vsftpd.user_list 中的用户无法登录;若设置为 NO,则只有在/etc/vsftpd.user_list 中的用 户才能登录。

(28)listen=YES

取值为 YES/NO。设置 FTP 服务器是否工作在 standalone 模式。若是工作在 xinetd 模式下,

必须设置为 NO。

(29)tcp_wrappers=YES

如果使用该选项(YES),会将 vsftpd 与 wrapper 相结合,这样可以利用/etc/hosts.allow 与 /etc/hosts.deny 文件来定义允许或拒绝的来源地址。默认不使用该项。

(30)max_clients = 0

如果 vsftpd 在 standalone 模式下启动,该处的设置表示可同时连接的最大客户端数量,其 后的任何客户端尝试连接时都会收到错误信息,“0”表示不受限制。

[lihh@rh9 lihh]$ ftp host1.cqcet.cn Connected to host1.cqcet.cn.

421 There are too many connected users, please try later.

(31)max_per_ip= 0

[root@rh9 root]# more /etc/vsftpd.ftpuser

# Users that are not allowed to login via ftp root

该配置文件只有在主配置文件/etc/vsftpd/vsftpd.conf 中的 userlist_enable 被设置为 YES 时

才起作用。同时,系统会根据/etc/vsftpd/vsftpd.conf 文件中的 userlist_deny 为 Yes 还是 No 来决 定是禁止/etc/vsftpd.user_list 中的用户登录,还是仅仅允许该文件中的用户登录。

下面是/etc/vsftpd.user_list 的初始内容,默认情况下里面列举出来的用户是被禁止登录 FTP 服务器的,可以看到 root 也是被禁止的。

[root@rh9 root]# more /etc/vsftpd.user_list

#vsftpd userlist

# If userlist_deny=NO, only allow users in this file

# If userlist_deny=YES (default), never allow users in this file, and

# do not even prompt for a password.

# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers

# for users that are denied.

root

[root@rh9 root]# service vsftpd start

为 vsftpd 启动 vsftpd: [ 确定 ] [root@rh9 root]# service vsftpd stop

关闭 vsftpd: [ 确定 ] [root@rh9 root]# service vsftpd status

vsftpd 已停

2.使用 chkconfig 命令

若要系统每次启动时自动开启 vsftpd 服务,可以使用如下命令,下面的例子表示在系统 进入第 3 和第 5 个级别时自动开启 vsftpd 服务。

[root@rh9 root]# chkconfig --level 35 vsftpd on [root@rh9 root]# chkconfig --list vsftpd

vsftpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭 8.4.5 访问 VSFTP 服务器

在成功安装以及启动 VSFTP 服务器后,客户端可以进行服务器的访问,常用的 FTP 客户

端工具有很多,下面仅介绍通过浏览器访问 FTP 服务器的方法。

浏览器除了浏览网页的功能外,也是连接 FTP 服务器最方便的客户端工具之一。使用浏 览器连接 FTP 服务器和连接 Web 服务器的方式很相似,唯一不同是使用的协议 ftp 而非 http。

浏览器除了浏览网页的功能外,也是连接 FTP 服务器最方便的客户端工具之一。使用浏 览器连接 FTP 服务器和连接 Web 服务器的方式很相似,唯一不同是使用的协议 ftp 而非 http。

相關文件