Centos 7裝vsftpd配置虛擬用戶

centos7.5 x86_64數據庫

yum install -y vsftpdcentos

創建Vsftpd虛擬宿主用戶:
useradd vsftpd -s /sbin/nologinsession

修改配置文件
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/vconfapp

創建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異步

新增虛擬用戶時,仍需再次執行該命令才生效socket

設定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/vusersasync

定製虛擬用戶模板配置文件
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。tcp

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  

相關文章
相關標籤/搜索