博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Centos 7装vsftpd配置虚拟用户
阅读量:5876 次
发布时间:2019-06-19

本文共 6632 字,大约阅读时间需要 22 分钟。

hot3.png

centos7.5 x86_64

yum install -y vsftpd

建立Vsftpd虚拟宿主用户:

useradd vsftpd -s /sbin/nologin

修改配置文件

cd /etc/vsftpd/ && cp vsftpd.conf{,.bak}

vi /etc/vsftpd/vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf
#
# 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
20端口进行数据传输
#
# 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=ftp
用系统自带的ftp用户作为vsftpd服务宿主用户,服务相关的文件权限应修改为本用户
#
# 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
支持ASCII模式的上传和下载功能
#
# 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=YES
关闭IPv6
pam_service_name=vsftpd  #启用pam认证
userlist_enable=YES  #userlist_file的用户不能登录FTP
tcp_wrappers=YES

开启虚拟用户

guest_enable=YES
指定虚拟用户宿主
guest_username=vsftpd
虚拟用户有宿主用户一样的权限
virtual_use_local_privs=YES
虚拟用户个人配置文件的存放路径,可个性定制权限
user_config_dir=/etc/vsftpd/vconf

建立vsftpd的上传下载日志文件

touch /var/log/xferlog
chown ftp.ftp /var/log/xferlog
建立虚拟用户配置文件目录
mkdir /etc/vsftpd/vconf/
建虚拟用户文件,格式:“一行用户名,一行口令”
touch /etc/vsftpd/vusers
vi /etc/vsftpd/vusers
user01
12345678
user02
12345678
生成虚拟用户数据文件
db_load -T -t hash -f /etc/vsftpd/vusers /etc/vsftpd/vusers.db

新增虚拟用户时,仍需再次执行该命令才生效

设定PAM验证文件,并指定虚拟用户数据库文件进行读取

cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bk
vi /etc/pam.d/vsftpd
注释掉原文后添加以下下内容(不注释掉所有原文,虚拟用户会登录不上)
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers

定制虚拟用户模板配置文件

vi /etc/vsftpd/vconf/vconf.tmp
local_root=/var/ftp/vuser  #不指定用户名虚拟用户登录后根目录是/home/vsftpd
#指定虚拟用户的具体主路径。
anonymous_enable=NO
#设定不允许匿名用户访问。
write_enable=YES
#设定允许写操作。
local_umask=022
#设定上传文件权限掩码。
anon_upload_enable=NO
#设定不允许匿名用户上传。
anon_mkdir_write_enable=NO
#设定不允许匿名用户建立目录。
idle_session_timeout=600
#设定空闲连接超时时间。
data_connection_timeout=120
#设定单次连续传输最大时间。
max_clients=10
#设定并发客户端访问个数。
max_per_ip=5
#设定单个客户端的最大线程数,这个配置主要来照顾Flashget、迅雷等多线程下载软件。
download_enable=YES
#可下载,不准改为NO
local_max_rate=50000
#设定该用户的最大传输速率,单位b/s。

cp vconf.tmp user01

用户拥有上传,下载,新建,删除权限
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
用户只拥有上传,下载,新建权限,不允许删除操作
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=NO

建立用户登录后的目录

cd /var/ftp/
mkdir user{01..02}
chown -R vsftpd.vsftpd /var/ftp/

启动vsftpd服务

systemctl start vsftpd
systemctl status vsftpd
 

转载于:https://my.oschina.net/u/2404183/blog/1933758

你可能感兴趣的文章
Silverlight开发历程—动画(线性动画)
查看>>
详解Linux中Load average负载
查看>>
HTTP 协议 Cache-Control 头——性能啊~~~
查看>>
丢包补偿技术概述
查看>>
PHP遍历文件夹及子文件夹所有文件
查看>>
WinForm程序中两份mdf文件问题的解决
查看>>
【转】唯快不破:创业公司如何高效的进行产品研发管理
查看>>
程序计数器、反汇编工具
查看>>
Android N: jack server failed
查看>>
007-Shell test 命令,[],[[]]
查看>>
关于Linux系统使用遇到的问题-1:vi 打开只读(readonly)文件如何退出保存?
查看>>
pandas 按照某一列进行排序
查看>>
在WPF中如何使用RelativeSource绑定
查看>>
Map的深浅拷贝的探究
查看>>
XSLT语法 在.net中使用XSLT转换xml文档示例
查看>>
如何将lotus 通讯簿导入到outlook 2003中
查看>>
WinForm 应用程序中开启新的进程及控制
查看>>
前端工程师的职业发展路线在哪?
查看>>
IOS 内存警告 Memory warning level
查看>>
[转]PAC Manager: Ubuntu 上强大的 SSH 帐号管理工具,可取代 SecureCRT_Miracle_百度空间...
查看>>