您的位置:首页 > 编程语言 > PHP开发

RHEL4- FTP服务(三)配置匿名用户访问VSFTPD服务器

2009-06-23 15:29 941 查看
RHEL4- FTP服务(三)配置匿名用户访问VSFTPD服务器

正如前文说《RHEL4- FTP服务(一)vsftpd的安装与启动 》,vsftpd服务默认安装完以后是直接可以使用的,当然在没有建立本地用户的时候只能使用匿名访问。单就匿名用户访问,如何才能灵活的控制匿名用户对文件、文件夹的上传、下载创建、删除和重命名呢?
下面我就把这一控制过程和大家一起聊一聊,说一说如何才能灵活的实现对匿名用户的控制以及如何配置。说到配置就不得不说一说vsftpd的一个重要文件那就是/etc/vsftpd/vsftpd.conf。我们无论是控制匿名用户还是本地用户或者是虚拟用户,都要在这一个配置文件中进行相应的调整,他就相当于整个服务的功能开关。在说之前我先让大家认识一下vsftpd.Conf这个配置文件中的四个匿名用户控制语句,
他们分别是:anon_upload_enable=(yes/no);
anon_world_readable_only=(yes/no);
anon_mkdir_write_enable=(yes/no);
anon_other_write_enable=(yes/no);
正是这四个主要语句控制这文件和文件夹的上传、下载、创建、删除和重命名。
***说明:如果以下语句有部分错误之处,还请在留言中指正。我会不断的测试修正!***

1、anon_upload_enable=yes/no(yes):(控制匿名用户文件上传,默认为yes)
Yes允许匿名用户有上传文件(非目录)的权限,且只有在write_enable=YES时,此项才有效,当然匿名用户必须要有对上层目录的写入权
No 匿名用户没有上传文件的权限;

2、anon_world_readable_only=yes/no(yes):(控制匿名用户文件的下载,默认配置文件中没有,需要手动添加)
Yes则允许匿名用户下载具有全球读权限的文件(非目录)可以下载到本机阅读,不能直接在FTP服务器中打开阅读;这将意味着ftp用户可以拥有自己的文件,特别是上传的文件。
NO不允许匿名用户下载文件

3、anon_mkdir_write_enable=yes/no(yes):(控制文件夹的创建,默认为yes)
Yes允许匿名用户创建文件夹或者目录,只有在write_enable=YES时,此项才有效。当然,匿名用户必须要有对上层目录的写入权;
NO不可以创建文件夹

4、anon_other_write_enable=(yes/no):(控制对文件和文件夹的删除和重命名,默认配置文件中没有该语句,需要手动添加。)
Yes允许匿名用户对文件、文件夹有除了上传和建立文件夹之外的权限,还有比如对文件和文件夹的删除和重命名的权限。通常建议不要添加或激活。
No不可以对文件和目录删除和重命名以及除了上传和建立文件夹之外的操作。

好!大家对这四个语句有一个大概的了解,下面我就把我配置的步骤和大家详细的说一说。

第一步,我们使用命令#vi /etc/vsftpd/vsftpd.conf打开vsftpd服务的配置文件。文件内容如下所示:



Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
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.
wirte_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
============================================================================================================================================
以上为安装vsftpd服务后默认的vsftpd.conf配置文件中的所有内容。

第二步:创建匿名用户文件存储目录
我们要创建存储你用用户上传下载文件或者文件夹的目录,默认情况下是/var/ftp,里面有一个默认的文件夹pub。Pub的默认权限如下图所示:


由上图我们可以看出,文件夹pub的拥有者是root,但是如果使用匿名用户进行上传下载,我们就要把这个文件夹的属主改为匿名用户。默认安装服务后,会自动创建一个匿名用户,那就是ftp,所用我们必须使用chown命令更改/var/ftp/pub文件夹的属主为ftp。具体操作如下图所示:


如果你不喜欢使用默认的文件夹,也可以自己使用mkdir命令重新创建一个,且用同样的方法把你自己创建的文件夹的属主更改为匿名用户ftp。

第三步:修改配置文件

在此说明一下,默认配置下,可以在ftp服务器上下载空目录。
1、检查anonymous_enable=YES/NO(YES)
控制是否允许匿名用户登入,YES 为允许匿名登入,NO 为不允许。默认值为YES。
2、检查write_enable=YES/NO(YES)
是否允许登陆用户有写权限。属于全局设置,默认值为YES。
3、去掉anon_upload_enable=yes/no(yes)前面的‘#’注释符号,使其语句生效。(此语句控制匿名用户文件上传,默认为yes)等号后面保持默认的‘yes’即可开启文件上传功能。
Yes允许匿名用户有上传文件(非目录)的权限,且只有在write_enable=YES时,此项才有效,当然匿名用户必须要有对上层目录的写入权
No 匿名用户没有上传文件的权限;

4、anon_world_readable_only=yes/no(yes):(此语句控制匿名用户文件的下载,默认配置文件中没有,需要手动添加)
Yes则允许匿名用户下载文件(非目录)可以下载到本机阅读,不能直接在FTP服务器中打开阅读;
NO不允许匿名用户下载文件

5、去掉anon_mkdir_write_enable=yes/no(yes)前面的‘#’注释符号:(此语句控制文件夹的创建,默认为yes)
Yes允许匿名用户创建文件夹,只有在write_enable=YES时,此项才有效。当然,匿名用户必须要有对上层目录的写入权;
NO不可以创建文件夹

6、anon_other_write_enable=(yes/no):(此语句控制对文件和文件夹的删除和重命名,默认配置文件中没有该语句,需要手动添加。)
Yes允许匿名用户对文件、文件夹有除了上传和建立文件夹之外的权限,比如对文件和文件夹的删除和重命名。
No不可以对文件和目录删除和重命名以及除了上传和建立文件夹之外的操作。

至此,你就可以利用上面的第3、4、5、6项灵活的控制匿名用户对文件和文件夹的上传、下载、创建、删除、重命名。

RHEL4- FTP服务(三)配置匿名用户访问VSFTPD服务器.pdf

—————————————————————————————————
特别声明:--
一、本文为原创,著作权及使用权为(作者笔名:闪电cto)本人所有。 ­
二、本文首发于51cto个人博客(http://xudeqiang.blog.51cto.com)。 ­
三、本文只供互联网上的读者分享,不供共享范畴,希知。 ­
四、未经许可严禁对本文作修改、节选、断章性质的处理。 ­
五、可转载,但必须注明原文章首发的出处网址,及文章作者,严禁复制。 ­
六、如若转摘用于杂志网络媒体新闻,必须通知作者得到允许后方可,需收稿费。­
七、作者联系信息:QQ:306718122 邮箱levinboy@foxmail.com
——————————————————————————————
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息