vsftpd服務 ftp是互聯網中進行文件傳輸的一種協議,基於C/S模式,FTP預設有兩個工作埠(20數據傳輸,21FTP服務端就收客戶端發來的指令和) 安裝FTP服務 [root@haha-main-130 ~]# yum -y install vsftpd 配置文件位置及內容 [root@ha ...
vsftpd服務
ftp是互聯網中進行文件傳輸的一種協議,基於C/S模式,FTP預設有兩個工作埠(20數據傳輸,21FTP服務端就收客戶端發來的指令和)
安裝FTP服務
[root@haha-main-130 ~]# yum -y install vsftpd
配置文件位置及內容
[root@haha-main-130 ~]# 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=YES
#
# 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. 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
主要配置項
[root@haha-main-130 ~]# cat /etc/vsftpd/vsftpd.conf | grep -vE '^$|^#'
anonymous_enable=YES #是否允許匿名登錄
local_enable=YES #是否允許本地用戶登錄
write_enable=YES #是否允許寫入
local_umask=022 #掩碼值
dirmessage_enable=YES #是否允許記錄日誌
xferlog_enable=YES #是否允許記錄日誌
connect_from_port_20=YES #允許20埠連接
xferlog_file=/var/log/xferlog #日誌記錄文件位置
xferlog_std_format=YES
listen=YES #是否打開本地監聽
listen_ipv6=YES #ipv6監聽
pam_service_name=vsftpd #守護名稱
userlist_enable=YES #允許userlist文件內用戶登錄
tcp_wrappers=YES
vsftp匿名用戶模式
- 任何人不需要賬號密碼登錄
配置文件
1.允許匿名用戶登錄
anonymous_enable=YES
2.允許匿名用戶上傳文件
anon_upload_enable=YES
3.允許匿名用戶寫入、創建文件夾
anon_mkdir_write_enable=YES
4.允許匿名用戶修改文件名,刪除文件夾操作
anon_other_witer_enable=YES
vsftp本地用戶模式
- 基於linux的本地賬號密碼進行驗證,配置簡單,但是存在安全隱患
配置文件
[root@haha-main-130 ~]# cat /etc/vsftpd/vsftpd.conf | grep -Ev '^$|^#'
anonymous_enable=NO #關閉匿名用戶驗證模式
local_enable=YES
write_enable=YES
local_umask=022 #預設文件許可權
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
tcp_wrappers=YES
此時/etc/vsftpd/ftpuser
文件中的用戶名不允許登錄
vsftp虛擬用戶模式
- 單獨為FTP工具創建用戶資料庫,基於口令驗證賬號密碼的信息
- 安裝DB工具,能夠轉化普通文件為vsftpd識別的資料庫文件
yum -y install db4 db4-utils
- 創建用於驗證的數據文件
[root@haha-main-130 vsftpd]# cat db.txt
name1
111
name2
222
- 加密文件
[root@haha-main-130 vsftpd]# db_load -T -t hash -f /etc/vsftpd/db.txt /etc/vsftpd/db.db
[root@haha-main-130 vsftpd]# cat db.db
a Gߊ????
??Gߊ????e1? эh^?
эh^222name2[root@haha-main-130 vsftpd]#
- 創建虛擬用戶登錄後預設訪問的文件夾路徑,與linux中的本地用戶創建一個映射關係,防止
匿名用戶登陸之後創建文件提示用戶許可權問題
# 創建一個本地用戶,指定家目錄,禁止登錄bash
[root@haha-main-130 vsftpd]# useradd -d /var/ftp/v_ftpfir -s /sbin/nologin v_user
# 修改/var/ftp/v_ftpfir目錄屬性為600
[root@haha-main-130 ftp]# chmod -Rf 755 v_ftpfir/
# 修改/etc/vsftpd/ftpuser文件,禁止v_user用戶登錄
[root@haha-main-130 vsftpd]# echo 'v_user' >> /etc/vsftpd/ftpusers
- 修改PAM文件
/etc/pam.d/vsftpd
[root@haha-main-130 vsftpd]# cat /etc/pam.d/vsftpd
#%PAM-1.0
session optional pam_keyinit.so force revoke
auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth required pam_shells.so
auth include password-auth
account include password-auth
session required pam_loginuid.so
session include password-auth
# 添加如下兩行,db之後的參數為db_load之後的文件路徑,不需要添加尾碼名
auth required pam_userdb.so db=/etc/vsftpd/db
account required pam_userdb.so db=/etc/vsftpd/db
- 修改vsftpd主配置文件
/etc/vsftpd/vsftpd.conf
[root@haha-main-130 vsftpd]# grep -Ev '^$|^#' vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
tcp_wrappers=YES
# 添加如下配置
guest_enable=YES # 開啟虛擬用戶
guest_username=v_user # 指定虛擬用戶賬號(關聯的本地用戶)
allow_writeable_chroot=YES # 允許寫入數據
- 針對不同用戶設置不同的許可權
- name1 允許上床,新建,修改,查看,刪除
- name2 只讀
# 設置關聯許可權文件夾
mkdir /etc/vsftpd/v_user_dir
# 創建文件,設置許可權
[root@haha-main-130 v_user_dir]# pwd
/etc/vsftpd/v_user_dir
[root@haha-main-130 v_user_dir]# cat name1
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@haha-main-130 v_user_dir]# cat name2
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
[root@haha-main-130 v_user_dir]#
# 編輯vsftpd主配置文件,添加如下配置
[root@haha-main-130 v_user_dir]# echo 'user_config_dir=/etc/vsftpd/v_user_dir' >> /etc/vsftpd/vsftpd.conf
- 重啟服務
systemctl restart vsftpd
問題記錄
-
創建文件失敗
ftp> mkdir data 550 Create directory operation failed.
解決方法:
修改
/var/ftp/pub
文件夾所屬用戶以及所屬用戶組[root@haha-main-130 ftp]# pwd /var/ftp [root@haha-main-130 ftp]# chown -Rf ftp.ftp pub/ [root@haha-main-130 ftp]# ll 總用量 0 drwxr-xr-x 2 ftp ftp 6 6月 9 2021 pub