《VSftpd安裝和配置FTP虛擬用戶實踐》要點:
本文介紹了VSftpd安裝和配置FTP虛擬用戶實踐,希望對您有用。如果有疑問,可以聯系我們。
VSftpd英文全稱(Very Secure File Transfer Protocol Deamon),正如VSftpd官方宣傳中所說Probably the most secure and fastest FTP server for UNIX-like systems
.我相信這是大多數人選擇VSftpd來搭建Linux的FTP服務器的原因,當然ProFTPD用的人應該也不在少數.本文將以清晰直觀的方式介紹安裝VSftpd以及配置FTP虛擬用戶的過程,希望對大家有幫助.
$ yum -y install vsftpd* pam* db4* ftp
$ useradd vsftpd -s /sbin/nologin
默認的VSftpd的服務宿主用戶是root,但是這不符合安全性的需要.這里建立名字為vsftpd的用戶,用他來作為支持VSftpd的服務宿主用戶.由于該用戶僅用來支持VSftpd服務用,因此沒有許可他登陸系統的必要,并設定他為不能登陸系統的用戶.
$ useradd virtual -d /home/ftpdata/ -s /sbin/nologin
$ chown -R virtual:virtual /home/ftpdata/
VSftpd的虛擬用戶并不是系統用戶,也就是說這些FTP的用戶在系統中是不存在的.他們的總體權限其實是集中寄托在一個在系統中的某一個用戶身上的,所謂VSftpd的虛擬宿主用戶,就是這樣一個支持著所有虛擬用戶的宿主用戶.由于他支撐了FTP的所有虛擬的用戶,那么他本身的權限將會影響著這些虛擬的用戶,因此出于安全性的考慮,也要非常注意對該用戶的權限的控制,該用戶也絕對沒有登陸系統的必要,這里也設定他為不能登陸系統的用戶.
anonymous_enable=YES|NO
控制是否允許匿名用戶登錄,YES允許,NO不允許,默認值為YES.
ftp_username= username
匿名用戶所使用的系統用戶名.默認下,此參數在配置文件中不出現,值為ftp
no_anon_password=YES|NO
控制匿名用戶登入時是否需要密碼,YES不需要,NO需要.默認值為NO.
anon_root=path
設定匿名用戶的根目錄,即匿名用戶登入后,被定位到此目錄下.主配置文件中默認無此項,默認值為/var/ftp/.
anon_world_readable_only=YES|NO
控制是否只允許匿名用戶下載可閱讀文檔.YES,只允許匿名用戶下載可閱讀的文件.NO,允許匿名用戶瀏覽整個服務器的文件系統.默認值為YES.
anon_upload_enable=YES|NO
控制是否允許匿名用戶上傳文件,YES允許,NO不允許,默認是不設值,即為NO.除了這個參數外,匿名用戶要能上傳文件,還需要兩個條件:一,write_enable參數為YES;二,在文件系統上,FTP匿名用戶對某個目錄有寫權限.
anon_mkdir_write_enable=YES|NO
控制是否允許匿名用戶創建新目錄,YES允許,NO不允許,默認是不設值,即為NO.當然在文件系統上,FTP匿名用戶必需對新目錄的上層目錄擁有寫權限.
anon_other_write_enable=YES|NO
控制匿名用戶是否擁有除了上傳和新建目錄之外的其他權限,如刪除、更名等.YES擁有,NO不擁有,默認值為NO.
chown_uploads=YES|NO
是否修改匿名用戶所上傳文件的所有權.YES,匿名用戶所上傳的文件的所有權將改為另外一個不同的用戶所有,用戶由chown_username參數指定.此選項默認值為NO.
chown_username=whoever
指定擁有匿名用戶上傳文件所有權的用戶
local_enable=YES|NO
控制vsftpd所在的系統的用戶是否可以登錄vsftpd.默認值為YES.
local_root=
定義所有本地用戶的根目錄.當本地用戶登入時,將被更換到此目錄下.默認值為無.
user_config_dir=
定義用戶個人配置文件所在的目錄.用戶的個人配置文件為該目錄下的同名文件
chroot_list_enable=YES|NO
鎖定某些用戶在自家目錄中.即當這些用戶登錄后,不可以轉到系統的其他目錄,只能在自家目錄(及其子目錄)下.具體的用戶在chroot_list_file參數所指定的文件中列出.默認值為NO.
chroot_list_file=/etc/vsftpd/chroot_list
指出被鎖定在自家目錄中的用戶的列表文件.文件格式為一行一用戶.通常該文件是/etc/vsftpd/chroot_list.此選項默認不設置.
chroot_local_users=YES|NO
將本地用戶鎖定在自家目錄中.當此項被激活時,chroot_list_enable和chroot_local_users參數的作用將發生變化,chroot_list_file所指定文件中的用戶將不被鎖定在自家目錄.本參數被激活后,可能帶來安全上的沖突,特別是當用戶擁有上傳、shell訪問等權限時.因此,只有在確實了解的情況下,才可以打開此參數.默認值為NO.
passwd_chroot_enable =YES|NO
當此選項激活時,與chroot_local_user選項配合,chroot()容器的位置可以在每個用戶的基礎上指定.每個用戶的容器來源于/etc/passwd中每個用戶的自家目錄字段.默認值為NO.
listen_address=ip address
定義了在主機的哪個IP地址上監聽FTP請求
listen_port=port_value ?
指定FTP服務器監聽的端口號(控制端口),默認值為21.此選項在standalone模式下生效
port_enable=YES|NO
指定數據連接時模式,默認值為YES(PORT模式,NO為PASV模式)
connect_from_port_20=YES|NO
控制以PORT模式進行數據傳輸時是否使用20端口(ftp-data)
ftp_data_port=port number
設定ftp數據傳輸端口(ftp-data)值.默認值為20.此參數用于PORT FTP模式.
pasv_enable=YES|NO
YES,允許數據傳輸時使用PASV模式.NO,不允許使用PASV模式.默認值為YES.
pasv_min_port=port number
pasv_max_port=port number
設定在PASV模式下,建立數據傳輸所可以使用port范圍的下界和上界,0 表 ? ?示任意.默認值為0.把端口范圍設在比較高的一段范圍內,比如50000-60000,將有助于安全性的提高
pasv_address= ip address
此選項為一個數字IP地址,作為PASV命令的響應.默認值為none,即地址是從呼入的連接套接字(incoming connectd socket)中獲取.
ascii_upload_enable=YES|NO
控制是否允許使用ascii模式上傳文件,YES允許,NO不允許,默認為NO
ascii_download_enable=YES|NO
控制是否允許使用ascii模式下載文件,YES允許,NO不允許,默認為NO.
idle_session_timeout= numerical value
空閑用戶會話的超時時間,若是超出這時間沒有數據的傳送或是指令的輸入,則會強迫斷線.單位為秒,默認值為300.
data_connection_timeout= numerical value
空閑的數據連接的超時時間.默認值為300 秒.
accept_timeout=numerical value
接受建立聯機的超時設定,單位為秒.默認值為60.
connect_timeout=numerical value
響應PORT方式的數據聯機的超時設定,單位為秒.默認值為60
max_clients=numerical value
此參數在VSFTPD使用單獨(standalone)模式下有效.此參數定義了FTP服務器最大的并發連接數,當超過此連接數時,服務器拒絕客戶端連接.默認值為0,表示不限最大連接數.
max_per_ip=numerical value
此參數在VSFTPD使用單獨(standalone)模式下有效.此參數定義每個IP地址最大的并發連接數目.超過這個數目將會拒絕連接.此選項的設置將影響到象網際快車這類的多進程下載軟件.默認值為0,表示不限制.
anon_max_rate=value
設定匿名用戶的最大數據傳輸速度value,以Bytes/s為單位.默認無.
local_max_rate=value
設定用戶的最大數據傳輸速度value,以Bytes/s為單位.默認無.
write_enable=YES
設定允許進行寫操作(上傳、刪除),默認為YES,可選值【yes,no】
local_umask=022
設定權限掩碼,默認022,對應的文件上傳權限644、目錄權限755
dirmessage_enable=YES
設定開啟目錄標語功能
xferlog_enable=YES
設定開啟日志記錄功能
xferlog_file=/var/log/ftp/vsftpd.log
設置日志目錄
xferlog_std_format=YES
設定日志使用標準的記錄格式
nopriv_user=vsftpd
設定支撐Vsftpd服務的宿主用戶為手動建立的Vsftpd用戶.注意,一旦做出更改宿主用戶后,必須注意一起與該服務相關的讀寫文件的讀寫賦權問題.比如日志文件就必須給與該用戶寫入權限等.
async_abor_enable=YES
設定支持異步傳輸功能.
ftpd_banner=This Vsftp server supports virtual users ^_^
設定Vsftpd的登陸標語.
deny_email_enable=YES
可將某些特殊的 email address 抵擋住.如果以anonymous 登錄服務器時,會要求輸入密碼,也就是您的email address, 如果很討厭某些email address ,就可以使用此設定來取消他的登錄權限,但必須與下面的設置項配合
banned_email_file=/etc/vsftpd/banned_emails
當上面的 deny_email_enable=YES 時,可以利用這個設定項來規定那個email address 不可登錄vsftpd 服務器,此文件需用戶自己創建,一行一個email address 即可!
ls_recurse_enable=YES
是否允許遞歸查詢 , 大型站點的 FTP 服務器啟用此項可以方便遠程用戶查詢
chroot_local_user=YES
listen=YES
如果設置為 YES , 則 vsftpd 將以獨立模式運行,由vsftpd 自己監聽和處理連接請求
listen_ipv6=YES
設定是否支持IPV6
pam_service_name=vsftpd
設置 PAM 外掛模塊提供的認證服務所使用的配置文件名 ,即/etc/pam.d/vsftpd 文件,此文件中file=/etc/vsftpd/ftpusers 字段,說明了PAM 模塊能抵擋的帳號內容來自文件/etc/vsftpd/ftpusers 中
userlist_enable=YES/NO
此選項默認值為NO , 此時ftpusers 文件中的用戶禁止登錄FTP 服務器;若此項設為YES ,則 user_list 文件中的用戶允許登錄 FTP 服務器,而如果同時設置了 userlist_deny=YES ,則 user_list 文件中的用戶將不允許登錄FTP 服務器,甚至連輸入密碼提示信息都沒有,直接被FTP 服務器拒絕
userlist_deny=YES/NO
此項默認為YES ,設置是否阻扯user_list 文件中的用戶登錄FTP 服務器
tcp_wrappers=YES
表明服務器使用 tcp_wrappers 作為主機訪問控制方式,tcp_wrappers 可以實現linux 系統中網絡服務的基于主機地址的訪問控制,在/etc 目錄中的hosts.allow 和hosts.deny 兩個文件用于設置tcp_wrappers 的訪問控制,前者設置允許訪問記錄,后者設置拒絕訪問記錄.例如想限制某些主機對FTP 服務器192.168.57.2 的匿名訪問,編緝/etc/hosts.allow 文件,如在下面增加兩行命令:vsftpd:192.168.57.1:DENY 和vsftpd:192.168.57.9:DENY 表明限制IP 為192.168.57.1/192.168.57.9 主機訪問IP 為192.168.57.2 的FTP 服務器,此時FTP 服務器雖可以PING 通,但無法連接
ftpusers:禁止user_list列表中的用戶訪問FTP
userlist_enable=YES,userlist_deny=YES,禁止user_list列表中的用戶訪FTP
userlist_enable=YES,userlist_deny=NO,只允許user_list列表中的用戶FTP.
userlist_enable=NO,userlist_deny=YES,因設定userlist_enable=NO,忽略user_list文件,user_list不啟作用
userlist_enable=NO,userlist_deny=NO,因設定userlist_enable=NO,忽略user_list文件,user_list不啟作用
ftpusers禁止的優先級更高.假設ftpusers禁止woodie用戶訪問,userlist允許woodie用戶訪問,則在運行時,用戶woodie不能訪問ftp.
$ vim /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.
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.
#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
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
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
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
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().
#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
#listen_port=56880
pasv_min_port=30000
pasv_max_port=35000
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd whith two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd.vu
#pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
chroot_local_user=YES
guest_enable=YES
guest_username=virtual
virtual_use_local_privs=YES
#reverse_lookup_enable=NO
user_config_dir=/etc/vsftpd/vsftpd_user_conf
$ vim /etc/vsftpd/ftpuser.txt
ftpupload
12345678
格式很簡單:”一行用戶名,一行密碼!”.
db_load命令可以將用戶文本信息文件轉換為db數據庫并使用hash加密.
選項-T允許應用程序能夠將文本文件轉譯載入進數據庫.由于我們之后是將虛擬用戶的信息以文件方式存儲在文件里的,為了讓Vsftpd這個應用程序能夠通過文本來載入用戶數據,必須要使用這個選項.
指定了選項-T,那么一定要追加子選項-t ; 子選項-t,追加在在-T選項后,用來指定轉譯載入的數據庫類型.hash就是使用hash碼加密.
-f參數后面接包含用戶名和密碼的文本文件,文件的內容是:奇數行用戶名、偶數行密碼;
$ db_load -T -t hash -f /etc/vsftpd/ftpuser.txt /etc/vsftpd/vsftpd_login.db
$ chmod 600 /etc/vsftpd/vsftpd_login.db
如果要刪除掉一個虛擬用戶,先在ftpuser.txt中刪除用戶對應的用戶名和密碼,然后刪除vsftpd_login.db,重新運行
db_load -T -t hash -f /etc/vsftpd/ftpuser.txt /etc/vsftpd/vsftpd_login.db
如果更改密碼,更改文件內容后還需重新運行db_load就可以,并重啟ftp服務使其生效.
如果要改變用戶的其它配置,只需修改用戶的配置文件.
$ vim /etc/pam.d/vsftpd.vu
將以下內容加入到文件最前面(在后面加入無效)
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
上一步建立的數據庫vsftpd_login在此處被使用,建立的虛擬用戶將采用PAM進行驗證,這是通過/etc/vsftpd/vsftpd.conf
文件中的語句pam_service_name=vsftpd.vu
來啟用的.
$ mkdir -p /etc/vsftpd/vsftpd_user_conf
$ vim /etc/vsftpd/vsftpd_user_conf/ftpupload
anon_world_readable_only=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_root=/home/ftpdata/
有時候可能需要開啟VSftpd服務器之間的站點對傳功能,只需在主配置文件/etc/vsftpd/vsftpd.conf
里加入如下參數即可
pasv_promiscuous=YES
port_promiscuous=YES
說明
port_promiscuous=YES|NO
默認值為NO.為YES時,取消PORT安全檢查.該檢查確保外出的數據只能連接到客戶端上.小心打開此選項.pasv_promiscuous=YES|NO
默認值為NO.為YES時,將關閉PASV模式的安全檢查.該檢查確保數據連接和控制連接是來自同一個IP地址.小心打開此選項.此選項唯一合理的用法是存在于由安全隧道方案構成的組織中.
由于取消了數據包的安全檢查,允許數據流向非客戶端,所以站點對傳成功.
配置修改完成后,重啟vsftpd服務生效
$ /etc/init.d/vsftpd restart
VSftpd與log有關的選項
vsftpd_log_file
xferlog_enable
xferlog_std_format
xferlog_file
dual_log_enable
syslog_enable
log_ftp_protocol
no_log_lock
這里主要要到下面幾個參數控制
log_ftp_protocol
如果啟用, 假若選項xferlog_std_format沒有啟用, 所有的FTP請求和應答都會被記錄. 此選項將對調試很有用.
默認: YESdual_log_enable
如果啟用, 將生成兩個相似的日志文件, 默認在/var/log/xferlog和/var/log/vsftpd.log目錄下. 前者是wu-ftpd類型的傳輸日志, 可以用于標準工具分析. 后者是vsftpd自己類型的日志.xferlog_enable
如果啟用, 將會維護一個日志文件, 用于詳細記錄上載和下載. 默認情況下, 這個日志文件是/var/log/vsftpd.log. 但是也可以通過配置文件中的vsftpd_log_file選項來指定.
默認: NO(但是在示例設置中啟用了這個選項)xferlog_std_format
如果啟用, 傳輸日志文件將以標準xferlog的格式書寫, 如同wu-ftpd一樣. 這可以用于重新使用傳輸統計生成器. 然而, 默認格式更注重可讀性. 此格式的日志文件默認為/var/log/xferlog, 但是您也可以通過xferlog_file選項來設定.
默認: NOxferlog_file
xferlog 日志文件所在位置,默認為/var/log/xferlog.vsftpd_log_file
指定VSFTPd日志文件位置,默認為/var/log/vsftpd.log,xferlog_enable的默認值為no(VSFTPd提供的配置文件模版將其值改為了yes),dual_log_enable的默認值也為no,就是說默認情況下VSFTPd是不記錄日志的.我們也可以將日志信息寫入系統日志/var/log/messages中,使用如下參數:syslog_enable=yes/no
將xferlog_file前面的#號對掉,也就是把VSftpd的Log功能打開,這樣我們就能在/var/log目錄下查看xferlog.這是VSftpd日志功能,這對于我們來說是極為重要的.
##################log settings###################
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/xferlog
#
#log in two files /var/log/xferlog and /var/log/vsftpd.log
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
#log time setting
use_localtime=YES
#
###################end of log####################
VSftpd對同一個IP地址的同時連接數量默認是沒有限制的.在VSftpd中的max_per_ip選項是0,代表沒有限制.
如果你想限制同一個IP地址的同時連接數量,你需要修改/etc/vsftpd/vsftpd.conf
文件.以下是一個例子
pam_service_name=vsftpd
userlist_enable=YES
#enable for standalone mode
listen=YES
tcp_wrappers=YES
max_per_ip=2
在這個例子中,每一個主機最多只能有兩個連接.修改vsftpd.conf之后,你需要重啟VSftpd來讓它生效.
一旦達到最大連接數,同一個主機下對這個FTP服務器的其他連接會出現以下的錯誤信息.
421 There are too many connections from your internet address.
通過/etc/hosts.allow
定義允許的來源地址,/etc/hosts.deny
定義拒絕的來源地址.
配置示例
/etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
vsftpd: 123.103.47.0/255.255.255.0 218.240.63.0/255.255.255.0 59.46.172.0/255.255.255.0 10.0.0.0/255.0.0.0 60.2.80.0/255.255.255.0 218.249.230.0/255.255.255.0 160.10.0.0/255.255.0.0 218.246.69.0/255.255.255.0 125.35.3.0/255.255.255.0 : allow
/etc/hosts.deny
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
vsftpd : ALL : DENY
將tcp_wrappers=yes添加至/etc/vsftpd/vsftpd.conf
中
$ vi /etc/vsftpd/vsftpd.conf
tcp_wrappers=YES
重新啟動VSftpd
$ service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
如果配置中出現問題,請從以下幾方面檢查
setsebool -P ftp_home_dir=1
.http://www.google.com
http://www.ha97.com/4113.html
http://www.cnblogs.com/sztsian/archive/2011/08/23/2204102.html
文:Mike
文章出處:運維之美(微信公眾號ID:Hi-Linux)
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/4468.html