8.8 Day16 配置系统用户访问ftp

查看之前服务器端做的配置

首先改成NO,禁止匿名用户访问

由于禁止了匿名用户访问,所以之前配置的和匿名用户有关的都失效了,故将其都注释掉。

local_enable=YES    //是否允许系统用户访问FTP

完整的配置文件内容如下:

# 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=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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
#anon_other_write_enable=YES
#anon_root=/var/public
#
# 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/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#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
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

创建两个用户:

用这两个用户登录,先试试匿名用户还能否登录

系统用户访问FTP的特点:

默认访问自己的目录,并具有所有权限。

还可以切换到系统的其他目录。

由上图可知两个系统用户都可以随意地切换目录,这是非常危险的操作,故需对这种越权行为作出限制。

1、设置系统用户只能访问自己的主目录并具有所有权限,不能切换到系统其他目录。

需在配置文件中添加以下语句(两条权限必须同时写入,若只写第一条命令,那么系统用户在登录时提示登录失败)

chroot_local_user=YES   控制用户只能访问自己的主目录,不能切换到其他目录
allow_writeable_chroot=YES  允许写入

因为没有权限,所以登录失败

此时需要在配置文件中再添加一行

两个用户都测试一次,完成权限的约束,无法越权访问系统内的其他目录

约束权限之前执行pwd后的结果如下:

约束权限之后执行pwd后的结果如下:

创建文件夹成功

删除文件夹成功

1、设置系统用户访问指定目录,不允许切换到系统的其他目录,并具上传、下载、新建、  

删除的权限。

需在配置文件中添加以下语句

local_root=/mnt/public/ 设置系统用户访问ftp的默认目录
write_enable=YES        允许写入
chroot_local_user=YES   控制用户访问路径访问指定目录,不能切换到其他目录
allow_writeable_chroot=YES 允许写入

由于前面已经添加了其中的两条命令,故只需要再添加剩下的两条命令

local_root=/mnt/public/ 设置系统用户访问ftp的默认目录
write_enable=YES        允许写入

查看配置语句中的目录是否存在:

因为不存在该文件夹,故创建对应的文件夹:

接着做如下操作:

无法向其中写入文件夹

原因如下,文件夹的其他用户没有写入权限,故需赋权,但不要直接修改对应主目录的其他用户的权限,而是赋予对应用户ACL权限:

成功!

此时无法随意切换目录:

切换至另一用户stu1:

发现无法创建目录,因为前面只给用户student赋予了ACL权限,此时去给stu1也赋予ACL权限:

系统用户的最终访问权限取决于:

(1)FTP权限(即有无write_enable=YES,有,则可以写入)

(2)文件本身的权限

(3)selinux安全机制

若开启selinux的安全机制,则无法查看文件夹内容且无法创建文件

关闭selinux安全机制后就恢复了正常

但是此时若再新建一个用户stu2,可以发现stu2可以访问并查看文件内容,仅单纯无写入权限,此时我们不希望stu2能查看内容,则需要添加黑白名单功能:

开始准备黑白名单:

默认情况下,ftp服务器中所有系统用户都可以访问ftp,如何来限定只有指定的系统用户可以访问呢?vsftp中提供了两个与系统用户相关的配置文件:

/etc/vsftpd/ftpusers  提供了一份用于禁止登录的ftp用户列表(黑名单)。 此文件中包含的用户将被禁止登录vsftpd服务器,不管该用户是否在/etc/vfsftpd/user_list中出现。

/etc/vsftpd/user_list 提供了一份用于允许登录的ftp用户列表(白名单),此文件中包含的用户可能被禁止登录,可能被允许登录。

用户的最终访问权限具体在主配置文件vsftpd.conf中决定:

当存在userlist_enable=YES时,user_list文件生效。

当存在userlist_deny=YES时,则仅禁止列表中的帐户登录。

当存在userlist_deny=NO时,则允许列表中用户登录。  

其中:ftpusers文件的优先级要高于user_list文件,即如果一个用户同时存在于两个文件中,则被拒绝访问ftp。

在配置文件中启用黑名单和白名单

添加 stu2

因为配置文件中仅设置了userlist_enable=YES,故白名单加与不加都能正常登录,但加入了黑名单就没法登录。

进入配置文件

 

黑名单和白名单的使用:

配置文件中只有:userlist_enable=YES(默认就有的)

此时黑名单生效,只要出现在黑名单中的用户不能登陆。

配置文件中有:userlist_enable=YES(默认就有的)

                        userlist_deny=NO

此时只有白名单生效,只有出现在白名单的用户可以登录。

如果用户同时出现在黑白名单中,则黑名单生效。

  • 7
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值