vsftpd虚拟用户及其权限配置

365万博首页 2025-10-08 21:33:31 admin 访问量: 6774 评分: 486
vsftpd虚拟用户及其权限配置

目录

一、应用场景二、配置过程1、安装软件2、新建本地用户3、修改vsftpd的配置文件4、新建虚拟用户目录5、配置虚拟用户(1)创建虚拟用户列表文件(2)生成虚拟用户数据库(3)配置pam认证(4)创建每个虚拟用户的文件目录(5)创建虚拟用户配置文件

6、重启服务

三、测试

一、应用场景

使用虚拟用户实现vsftpd的权限控制 软件版本

~ # vsftpd -version

vsftpd: version 3.0.2

~ #

二、配置过程

1、安装软件

yum install -y vsftpd db4

2、新建本地用户

新建一个本地用户,虚拟用户将映射到这个本地用户上.

useradd ftpuser

给这个本地用户配置密码

passwd ftpuser

3、修改vsftpd的配置文件

cat /etc/vsftpd/vsftpd.conf

# 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

#

# 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.

# 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=YES

#

# 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=NO

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

# 启用虚拟用户功能

guest_enable=YES

# 指定虚拟用户的宿主用户,CentOS中已经有内置的ftp用户了,此处使用上面新建的ftpuser

guest_username=ftpuser

# 配置虚拟用户路径,虚拟用户的配置文件放在该路径下

user_config_dir=/etc/vsftpd/vuser

# 配置vsftpd日志

xferlog_enable=YES

xferlog_std_format=YES

xferlog_file=/var/log/xferlog

dual_log_enable=YES

vsftpd_log_file=/var/log/vsftpd.log

allow_writeable_chroot=YES

pasv_enable=yes

pasv_min_port=2000

pasv_max_port=2020

4、新建虚拟用户目录

在vsftp.conf中,配置的虚拟用户目录为:user_config_dir=/etc/vsftpd/vuser,现在新建虚拟用户目录,每个虚拟用户的配置文件都放这个目录下

mkdir /etc/vsftpd/vuser

5、配置虚拟用户

(1)创建虚拟用户列表文件

cat /etc/vsftpd/virtual_users.txt

ftp1 #用户名

ftp1 #用户ftp1的密码,以此类推,创建了三个用户

ftp2

ftp2

ftp3

ftp3

(2)生成虚拟用户数据库

# 生成虚拟用户数据库文件

db_load -T -t hash -f /etc/vsftpd/virtual_users.txt /etc/vsftpd/virtual_users.db

# 设置数据库文件权限

chmod 600 /etc/vsftpd/virtual_users.db

(3)配置pam认证

/etc/vsftpd/virtual_users是指文件/etc/vsftpd/virtual_users.db,.db要省略

cat /etc/pam.d/vsftpd

auth required pam_userdb.so db=/etc/vsftpd/virtual_users

account required pam_userdb.so db=/etc/vsftpd/virtual_users

(4)创建每个虚拟用户的文件目录

创建三个目录,作为三个ftp用户的文件根目录,因为这三个虚拟用户映射到了本地用户ftpuser,所以这三个虚拟用户的文件根目录的属主属组要改为ftpuser,否则会有权限问题

mkdir -p /data/ftp/{fpt1,fpt2,fpt3}

chown -R ftpuser:ftpuser /data/ftp/{ftp1,ftp2,ftp3}

chmod 755 /data/ftp/{ftp1,ftp2,ftp3}

(5)创建虚拟用户配置文件

ftp1的权限为:上传、下载 cat /etc/vsftpd/vuser/ftp1

local_root=/data/ftp/ftp1 #用户ftp1的文件根目录

# 上述挂载的磁盘,目录属主和属组必须为ftpuser,即映射的本地用户

write_enable=YES

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

ftp2的权限为:仅上传 cat /etc/vsftpd/vuser/ftp2

local_root=/data/ftp/ftp2

write_enable=YES

anon_world_readable_only=NO

download_enable=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

ftp3的权限为:仅下载 cat /etc/vsftpd/vuser/ftp3

local_root=/data/ftp/ftp3

write_enable=NO

anon_world_readable_only=NO

anon_upload_enable=NO

anon_mkdir_write_enable=NO

anon_other_write_enable=NO

6、重启服务

systemctl restart vsftpd

三、测试

在三个虚拟用户的文件根目录下新建测试文件

touch /data/ftp/fpt1/ftp1file

touch /data/ftp/fpt2/ftp2file

touch /data/ftp/fpt3/ftp3file

在客户端新建测试目录和文件

# pwd

/root/ftptset

# touch test.pdf

# ls

test.pdf

在客户端分别使用三个虚拟用户账号登录vsftpd服务器 ftp1(上传下载):

[root@client:~/ftptset]

# lftp -u ftp1,ftp1 ftp://192.168.8.8

lftp ftp1@192.168.8.8:~> ls

-rw------- 1 1002 1002 0 Dec 29 11:52 1.txt

-rw-r--r-- 1 0 0 0 Dec 29 13:23 ftp1file

-rw-r--r-- 1 1002 1002 0 Dec 29 11:22 test

lftp ftp1@192.168.8.8:/> get ftp1file # 下载文件

lftp ftp1@192.168.8.8:/> put test.pdf # 上传文件

lftp ftp1@192.168.8.8:/> ls

-rw------- 1 1002 1002 0 Dec 29 11:52 1.txt

-rw-r--r-- 1 0 0 0 Dec 29 13:23 ftp1file

-rw-r--r-- 1 1002 1002 0 Dec 29 11:22 test

-rw------- 1 1002 1002 0 Dec 29 13:31 test.pdf

lftp ftp1@192.168.8.8:/>

ftp2(仅上传):

# lftp -u ftp2,ftp2 ftp://192.168.8.8

lftp ftp2@192.168.8.8:~> ls

-rw-r--r-- 1 0 0 0 Dec 29 13:23 ftp2file

lftp ftp2@192.168.8.8:/> put test.pdf

lftp ftp2@192.168.8.8:/> ls

-rw-r--r-- 1 0 0 0 Dec 29 13:23 ftp2file

-rw------- 1 1002 1002 0 Dec 29 13:57 test.pdf

lftp ftp2@192.168.8.8:/> get ftp2file

get: Access failed: 550 Permission denied. (ftp2file)

lftp ftp2@192.168.8.8:/>

ftp3(仅下载):

# lftp -u ftp3,ftp3 ftp://192.168.8.8

lftp ftp3@192.168.8.8:~> ls

-rw-r--r-- 1 0 0 0 Dec 29 13:23 ftp3file

lftp ftp3@192.168.8.8:/> get ftp3file

lftp ftp3@192.168.8.8:/> put test.pdf

put: Access failed: 550 Permission denied. (test.pdf)

lftp ftp3@192.168.8.8:/>

相关数据

追字的成语有哪些
日博365官网网址多少

追字的成语有哪些

10-04 ↗ 4390
矽胶娃娃| 情趣娃娃| 成人娃娃|KD人形美术馆
日博365官网网址多少

矽胶娃娃| 情趣娃娃| 成人娃娃|KD人形美术馆

08-05 ↗ 480
草原牧场上的牛群图片素材
bst365体育娱乐平台

草原牧场上的牛群图片素材

08-15 ↗ 775
识字趣中学——小学低年段识字方法系列课程
日博365官网网址多少

识字趣中学——小学低年段识字方法系列课程

07-10 ↗ 2327
神途哪个版本好玩 好玩的神途版本排行榜TOP5
日博365官网网址多少

神途哪个版本好玩 好玩的神途版本排行榜TOP5

08-08 ↗ 4808
手机生意转让app排行榜TOP10推荐
日博365官网网址多少

手机生意转让app排行榜TOP10推荐

08-24 ↗ 9655
荣耀和华为手机哪个好?各推荐一款
bst365体育娱乐平台

荣耀和华为手机哪个好?各推荐一款

10-01 ↗ 6373