溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

vsftpd搭建和創(chuàng)建虛擬賬號(hào)

發(fā)布時(shí)間:2020-06-29 12:57:45 來(lái)源:網(wǎng)絡(luò) 閱讀:359 作者:加州貓大叔 欄目:數(shù)據(jù)庫(kù)

環(huán)境:CentOS 5.0 操作系統(tǒng)
一.安裝:
1.安裝Vsftpd服務(wù)相關(guān)部件:
[root@KcentOS5 ~]# yum install vsftpd*
Dependencies Resolved=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
vsftpd                  i386       2.0.5-10.el5     base              137 kTransaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
2.確認(rèn)安裝PAM服務(wù)相關(guān)部件:
[root@KcentOS5 ~]# yum install pam*
Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
pam-devel               i386       0.99.6.2-3.14.el5 base              186 kTransaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
開(kāi)發(fā)包,其實(shí)不裝也沒(méi)有關(guān)系,主要的目的是確認(rèn)PAM。
3.安裝DB4部件包:
這里要特別安裝一個(gè)db4的包,用來(lái)支持文件數(shù)據(jù)庫(kù)。
[root@KcentOS5 ~]# yum install db4*
Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
db4-devel               i386       4.3.29-9.fc6     base              2.0 M
db4-java                i386       4.3.29-9.fc6     base              1.7 M
db4-tcl                 i386       4.3.29-9.fc6     base              1.0 M
db4-utils               i386       4.3.29-9.fc6     base              119 kTransaction Summary
=============================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

二.系統(tǒng)帳戶(hù)
1.建立Vsftpd服務(wù)的宿主用戶(hù):
[root@KcentOS5 ~]# useradd vsftpd -s /sbin/nologin
默認(rèn)的Vsftpd的服務(wù)宿主用戶(hù)是root,但是這不符合安全性的需要。這里建立名字為vsftpd的用戶(hù),用他來(lái)作為支持Vsftpd的服務(wù)宿主用戶(hù)。由于該用戶(hù)僅用來(lái)支持Vsftpd服務(wù)用,因此沒(méi)有許可他登陸系統(tǒng)的必要,并設(shè)定他為不能登陸系統(tǒng)的用戶(hù)。

2.建立Vsftpd虛擬宿主用戶(hù):
[root@KcentOS5 nowhere]# useradd overlord -s /sbin/nologin
本篇主要是介紹Vsftp的虛擬用戶(hù),虛擬用戶(hù)并不是系統(tǒng)用戶(hù),也就是說(shuō)這些FTP的用戶(hù)在系統(tǒng)中是不存在的。他們的總體權(quán)限其實(shí)是集中寄托在一個(gè)在系統(tǒng)中的某一個(gè)用戶(hù)身上的,所謂Vsftpd的虛擬宿主用戶(hù),就是這樣一個(gè)支持著所有虛擬用戶(hù)的宿主用戶(hù)。由于他支撐了FTP的所有虛擬的用戶(hù),那么他本身的權(quán)限將會(huì)影響著這些虛擬的用戶(hù),因此,處于安全性的考慮,也要非分注意對(duì)該用戶(hù)的權(quán)限的控制,該用戶(hù)也絕對(duì)沒(méi)有登陸系統(tǒng)的必要,這里也設(shè)定他為不能登陸系統(tǒng)的用戶(hù)。(這里插一句:原本在建立上面兩個(gè)用戶(hù)的時(shí)候,想連用戶(hù)主路徑也不打算給的。本來(lái)想加上 -d /home/nowhere 的,據(jù)man useradd手冊(cè)上講述:“       -d, --home HOME_DIR
The new user will be created using HOME_DIR as the value for the
user鈙 login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name. The directory
HOME_DIR does not have to exist but will not be created if it is
missing.
使用-d參數(shù)指定用戶(hù)的主目錄,用戶(hù)主目錄并不是必須存在的。如果沒(méi)有存在指定的目錄的話,那么它將不會(huì)被建立”。

三.調(diào)整Vsftpd的配置文件:
1.編輯配置文件前先備份
[root@KcentOS5 ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.backup2.編輯主配置文件Vsftpd.conf
[root@KcentOS5 ~]# vi /etc/vsftpd/vsftpd.conf
這里我將原配置文件的修改完全記錄,凡是修改的地方我都會(huì)保留注釋原來(lái)的配置。其中加入我對(duì)每條配置項(xiàng)的認(rèn)識(shí),對(duì)于一些比較關(guān)鍵的配置項(xiàng)這里我做了我的觀點(diǎn),并且原本英語(yǔ)的說(shuō)明我也不刪除,供參考對(duì)比用。
------------------------------------------------------------------------------
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
#anonymous_enable=YES
anonymous_enable=NO
設(shè)定不允許匿名訪問(wèn)
#
# Uncomment this to allow local users to log in.
local_enable=YES
設(shè)定本地用戶(hù)可以訪問(wèn)。注意:主要是為虛擬宿主用戶(hù),如果該項(xiàng)目設(shè)定為NO那么所有虛擬用戶(hù)將無(wú)法訪問(wèn)。
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
設(shè)定可以進(jìn)行寫(xiě)操作。
#
# 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
設(shè)定上傳后文件的權(quán)限掩碼。
#
# 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
anon_upload_enable=NO
禁止匿名用戶(hù)上傳。
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
anon_mkdir_write_enable=NO
禁止匿名用戶(hù)建立目錄。
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
設(shè)定開(kāi)啟目錄標(biāo)語(yǔ)功能。
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
設(shè)定開(kāi)啟日志記錄功能。
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
設(shè)定端口20進(jìn)行數(shù)據(jù)連接。
#
# 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_uploads=NO
設(shè)定禁止上傳文件更改宿主。
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
設(shè)定Vsftpd的服務(wù)日志保存路徑。注意,該文件默認(rèn)不存在。必須要手動(dòng)touch出來(lái),并且由于這里更改了Vsftpd的服務(wù)宿主用戶(hù)為手動(dòng)建立的Vsftpd。必須注意給與該用戶(hù)對(duì)日志的寫(xiě)入權(quán)限,否則服務(wù)將啟動(dòng)失敗。
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES
設(shè)定日志使用標(biāo)準(zhǔn)的記錄格式。
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
設(shè)定空閑連接超時(shí)時(shí)間,這里使用默認(rèn)。將具體數(shù)值留給每個(gè)具體用戶(hù)具體指定,當(dāng)然如果不指定的話,還是使用這里的默認(rèn)值600,單位秒。
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
設(shè)定單次最大連續(xù)傳輸時(shí)間,這里使用默認(rèn)。將具體數(shù)值留給每個(gè)具體用戶(hù)具體指定,當(dāng)然如果不指定的話,還是使用這里的默認(rèn)值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
nopriv_user=vsftpd
設(shè)定支撐Vsftpd服務(wù)的宿主用戶(hù)為手動(dòng)建立的Vsftpd用戶(hù)。注意,一旦做出更改宿主用戶(hù)后,必須注意一起與該服務(wù)相關(guān)的讀寫(xiě)文件的讀寫(xiě)賦權(quán)問(wèn)題。比如日志文件就必須給與該用戶(hù)寫(xiě)入權(quán)限等。
#
# 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
設(shè)定支持異步傳輸功能。
#
# 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
設(shè)定支持ASCII模式的上傳和下載功能。
#
# You may fully customise the login banner string:
ftpd_banner=This Vsftp server supports virtual users ^_^
設(shè)定Vsftpd的登陸標(biāo)語(yǔ)。
#
# 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
chroot_list_enable=NO
禁止用戶(hù)登出自己的FTP主目錄。
# (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
ls_recurse_enable=NO
禁止用戶(hù)登陸FTP后使用"ls -R"的命令。該命令會(huì)對(duì)服務(wù)器性能造成巨大開(kāi)銷(xiāo)。如果該項(xiàng)被允許,那么擋多用戶(hù)同時(shí)使用該命令時(shí)將會(huì)對(duì)該服務(wù)器造成威脅。
# 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
設(shè)定該Vsftpd服務(wù)工作在StandAlone模式下。順便展開(kāi)說(shuō)明一下,所謂StandAlone模式就是該服務(wù)擁有自己的守護(hù)進(jìn)程支持,在ps -A命令下我們將可用看到vsftpd的守護(hù)進(jìn)程名。如果不想工作在StandAlone模式下,則可以選擇SuperDaemon模式,在該模式下 vsftpd將沒(méi)有自己的守護(hù)進(jìn)程,而是由超級(jí)守護(hù)進(jìn)程Xinetd全權(quán)代理,與此同時(shí),Vsftp服務(wù)的許多功能將得不到實(shí)現(xiàn)。
#
# 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=YESpam_service_name=vsftpd
設(shè)定PAM服務(wù)下Vsftpd的驗(yàn)證配置文件名。因此,PAM驗(yàn)證將參考/etc/pam.d/下的vsftpd文件配置。
userlist_enable=YES
設(shè)定userlist_file中的用戶(hù)將不得使用FTP。
tcp_wrappers=YES
設(shè)定支持TCP Wrappers。#KC: The following entries are added for supporting virtual ftp users.
以下這些是關(guān)于Vsftpd虛擬用戶(hù)支持的重要配置項(xiàng)目。默認(rèn)Vsftpd.conf中不包含這些設(shè)定項(xiàng)目,需要自己手動(dòng)添加配置。guest_enable=YES
設(shè)定啟用虛擬用戶(hù)功能。
guest_username=overlord
指定虛擬用戶(hù)的宿主用戶(hù)。
virtual_use_local_privs=YES
設(shè)定虛擬用戶(hù)的權(quán)限符合他們的宿主用戶(hù)。
user_config_dir=/etc/vsftpd/vconf
設(shè)定虛擬用戶(hù)個(gè)人Vsftp的配置文件存放路徑。也就是說(shuō),這個(gè)被指定的目錄里,將存放每個(gè)Vsftp虛擬用戶(hù)個(gè)性的配置文件,一個(gè)需要注意的地方就是這些配置文件名必須和虛擬用戶(hù)名相同。

pam_service_name=vsftpd     # 指定pam模塊名(可以自定義)

-------------------------------------------------------------------------
保存退出。
2.建立Vsftpd的日志文件,并更該屬主為Vsftpd的服務(wù)宿主用戶(hù):
[root@KcentOS5 ~]# touch /var/log/vsftpd.log
[root@KcentOS5 ~]# chown vsftpd.vsftpd /var/log/vsftpd.log 4.建立虛擬用戶(hù)配置文件存放路徑:
[root@KcentOS5 ~]# mkdir /etc/vsftpd/vconf/
三.制作虛擬用戶(hù)數(shù)據(jù)庫(kù)文件
1.先建立虛擬用戶(hù)名單文件:
[root@KcentOS5 ~]# touch /etc/vsftpd/virtusers
建立了一個(gè)虛擬用戶(hù)名單文件,這個(gè)文件就是來(lái)記錄vsftpd虛擬用戶(hù)的用戶(hù)名和口令的數(shù)據(jù)文件,我這里給它命名為virtusers。為了避免文件的混亂,我把這個(gè)名單文件就放置在/etc/vsftpd/下。

2.編輯虛擬用戶(hù)名單文件:
[root@KcentOS5 ~]# vi /etc/vsftpd/virtusers
----------------------------
kanecruise
123456
near
123456near
mello
123456mello
----------------------------
編輯這個(gè)虛擬用戶(hù)名單文件,在其中加入用戶(hù)的用戶(hù)名和口令信息。格式很簡(jiǎn)單:“一行用戶(hù)名,一行口令”。

3.生成虛擬用戶(hù)數(shù)據(jù)文件:
[root@KcentOS5 ~]# db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
這里我順便把這個(gè)命令簡(jiǎn)單說(shuō)明一下
----------------------------------------------------------------------
察看db4的db_load命令使用方法:
[root@KSRV2 vsftpd]# db_load
usage: db_load [-nTV] [-c name=value] [-f file]
[-h home] [-P password] [-t btree | hash | recno | queue] db_file
usage: db_load -r lsn | fileid [-h home] [-P password] db_file
解釋在本篇中,db_load命令幾個(gè)相關(guān)選項(xiàng)很參數(shù)-T
The -T option allows non-Berkeley DB applications to easily load text files into databases.
If the database to be created is of type Btree or Hash, or the keyword keys is specified as set, the input must be paired lines of text, where the first line of the pair is the key item, and the second line of the pair is its corresponding data item. If the database to be created is of type Queue or Recno and the keywork keys is not set, the input must be lines of text, where each line is a new data item for the database.
選項(xiàng)-T允許應(yīng)用程序能夠?qū)⑽谋疚募D(zhuǎn)譯載入進(jìn)數(shù)據(jù)庫(kù)。由于我們之后是將虛擬用戶(hù)的信息以文件方式存儲(chǔ)在文件里的,為了讓Vsftpd這個(gè)應(yīng)用程序能夠通過(guò)文本來(lái)載入用戶(hù)數(shù)據(jù),必須要使用這個(gè)選項(xiàng)。If the -T option is specified, the underlying access method type must be specified using the -t option.
如果指定了選項(xiàng)-T,那么一定要追跟子選項(xiàng)-t-t
Specify the underlying access method. If no -t option is specified, the database will be loaded into a database of the same type as was dumped; for example, a Hash database will be created if a Hash database was dumped.
Btree and Hash databases may be converted from one to the other. Queue and Recno databases may be converted from one to the other. If the -k option was specified on the call to db_dump then Queue and Recno databases may be converted to Btree or Hash, with the key being the integer record number.
子選項(xiàng)-t,追加在在-T選項(xiàng)后,用來(lái)指定轉(zhuǎn)譯載入的數(shù)據(jù)庫(kù)類(lèi)型。擴(kuò)展介紹下,-t可以指定的數(shù)據(jù)類(lèi)型有Btree、Hash、Queue和Recon數(shù)據(jù)庫(kù)。這里,接下來(lái)我們需要指定的是Hash型。
----------------------------------------------------------------------------

4.察看生成的虛擬用戶(hù)數(shù)據(jù)文件
[root@KcentOS5 ~]# ll /etc/vsftpd/virtusers.db
-rw-r--r-- 1 root root 12288 Sep 16 03:51 /etc/vsftpd/virtusers.db
需要特別注意的是,以后再要添加虛擬用戶(hù)的時(shí)候,只需要按照“一行用戶(hù)名,一行口令”的格式將新用戶(hù)名和口令添加進(jìn)虛擬用戶(hù)名單文件。但是光這樣做還不夠,不會(huì)生效的哦!還要再執(zhí)行一遍“ db_load -T -t hash -f 虛擬用戶(hù)名單文件 虛擬用戶(hù)數(shù)據(jù)庫(kù)文件.db ”的命令使其生效才可以!

四.設(shè)定PAM驗(yàn)證文件,并指定虛擬用戶(hù)數(shù)據(jù)庫(kù)文件進(jìn)行讀取
1.察看原來(lái)的Vsftp的PAM驗(yàn)證配置文件:
[root@KcentOS5 ~]# 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      system-auth
account    include      system-auth
session    include      system-auth
session    required     pam_loginuid.so
----------------------------------------------------------------

2.在編輯前做好備份:
[root@KcentOS5 ~]# cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.backup3.編輯Vsftpd的PAM驗(yàn)證配置文件
[root@KcentOS5 ~]# vi /etc/pam.d/vsftpd
----------------------------------------------------------------
#%PAM-1.0
auth    sufficient      /lib64/security/pam_userdb.so     db=/etc/vsftpd/virtusers
account sufficient      /lib64/security/pam_userdb.so     db=/etc/vsftpd/virtusers
以上兩條是手動(dòng)添加的,內(nèi)容是對(duì)虛擬用戶(hù)的安全和帳戶(hù)權(quán)限進(jìn)行驗(yàn)證。
這里的auth是指對(duì)用戶(hù)的用戶(hù)名口令進(jìn)行驗(yàn)證。
這里的accout是指對(duì)用戶(hù)的帳戶(hù)有哪些權(quán)限哪些限制進(jìn)行驗(yàn)證。
其后的sufficient表示充分條件,也就是說(shuō),一旦在這里通過(guò)了驗(yàn)證,那么也就不用經(jīng)過(guò)下面剩下的驗(yàn)證步驟了。相反,如果沒(méi)有通過(guò)的話,也不會(huì)被系統(tǒng)立即擋之門(mén)外,因?yàn)閟ufficient的失敗不決定整個(gè)驗(yàn)證的失敗,意味著用戶(hù)還必須將經(jīng)歷剩下來(lái)的驗(yàn)證審核。
再后面的/lib/security/pam_userdb.so表示該條審核將調(diào)用pam_userdb.so這個(gè)庫(kù)函數(shù)進(jìn)行。
最后的db=/etc/vsftpd/virtusers則指定了驗(yàn)證庫(kù)函數(shù)將到這個(gè)指定的數(shù)據(jù)庫(kù)中調(diào)用數(shù)據(jù)進(jìn)行驗(yàn)證。
#KC: The entries for Vsftpd-PAM are added above.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      system-auth
account    include      system-auth
session    include      system-auth
session    required     pam_loginuid.so
----------------------------------------------------------------
五.虛擬用戶(hù)的配置
1.規(guī)劃好虛擬用戶(hù)的主路徑:
[root@KcentOS5 ~]# mkdir /opt/vsftp/

2.建立測(cè)試用戶(hù)的FTP用戶(hù)目錄:
[root@KcentOS5 ~]# mkdir /opt/vsftp/kanecruise/ /opt/vsftp/mello/ /opt/vsftp/near/

3.建立虛擬用戶(hù)配置文件模版:[root@KcentOS5 ~]# cp /etc/vsftpd/vsftpd.conf.backup /etc/vsftpd/vconf/vconf.tmp

4.定制虛擬用戶(hù)模版配置文件:
[root@KcentOS5 ~]# vi /etc/vsftpd/vconf/vconf.tmp
--------------------------------
local_root=/opt/vsftp/virtuser
指定虛擬用戶(hù)的具體主路徑。
anonymous_enable=NO
設(shè)定不允許匿名用戶(hù)訪問(wèn)。
write_enable=YES
設(shè)定允許寫(xiě)操作。
local_umask=022
設(shè)定上傳文件權(quán)限掩碼。
anon_upload_enable=NO
設(shè)定不允許匿名用戶(hù)上傳。
anon_mkdir_write_enable=NO
設(shè)定不允許匿名用戶(hù)建立目錄。
idle_session_timeout=600
設(shè)定空閑連接超時(shí)時(shí)間。
data_connection_timeout=120
設(shè)定單次連續(xù)傳輸最大時(shí)間。
max_clients=10
設(shè)定并發(fā)客戶(hù)端訪問(wèn)個(gè)數(shù)。
max_per_ip=5
設(shè)定單個(gè)客戶(hù)端的最大線程數(shù),這個(gè)配置主要來(lái)照顧Flashget、迅雷等多線程下載軟件。
local_max_rate=50000
設(shè)定該用戶(hù)的最大傳輸速率,單位b/s。
--------------------------------
這里將原vsftpd.conf配置文件經(jīng)過(guò)簡(jiǎn)化后保存作為虛擬用戶(hù)配置文件的模版。這里將并不需要指定太多的配置內(nèi)容,主要的框架和限制交由 Vsftpd的主配置文件vsftpd.conf來(lái)定義,即虛擬用戶(hù)配置文件當(dāng)中沒(méi)有提到的配置項(xiàng)目將參考主配置文件中的設(shè)定。而在這里作為虛擬用戶(hù)的配置文件模版只需要留一些和用戶(hù)流量控制,訪問(wèn)方式控制的配置項(xiàng)目就可以了。這里的關(guān)鍵項(xiàng)是local_root這個(gè)配置,用來(lái)指定這個(gè)虛擬用戶(hù)的FTP主路徑。5.更改虛擬用戶(hù)的主目錄的屬主為虛擬宿主用戶(hù):
[root@KcentOS5 ~]# chown -R overlord.overlord /opt/vsftp/6.檢查權(quán)限:
[root@KcentOS5 ~]# ll /opt/vsftp/
total 24
drwxr-xr-x 2 overlord overlord 4096 Sep 16 05:14 kanecruise
drwxr-xr-x 2 overlord overlord 4096 Sep 16 05:00 mello
drwxr-xr-x 2 overlord overlord 4096 Sep 16 05:00 near
六.給測(cè)試用戶(hù)定制:
1.從虛擬用戶(hù)模版配置文件復(fù)制:
[root@KcentOS5 ~]# cp /etc/vsftpd/vconf/vconf.tmp /etc/vsftpd/vconf/kanecruise

2.針對(duì)具體用戶(hù)進(jìn)行定制:
[root@KcentOS5 ~]# vi /etc/vsftpd/vconf/kanecruise
---------------------------------
local_root=/opt/vsftp/kanecruise
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=300
data_connection_timeout=90
max_clients=1
max_per_ip=1
local_max_rate=25000
---------------------------------

模板注釋?zhuān)?/p>

# cat /etc/vsftpconf/user1
local_root=/opt/vsftp/user1     # 指定用戶(hù)登錄目錄
anonymous_enable=NO             # 不允許匿名登錄
write_enable=YES                # 可寫(xiě)
local_umask=022                 # 掩碼為022
anon_upload_enable=NO           # 匿名用戶(hù)不可上傳
anon_mkdir_write_enable=NO      # 匿名用戶(hù)不可創(chuàng)建目錄
idle_session_timeout=300        # 會(huì)話超時(shí)時(shí)間300秒
data_connection_timeout=90      # 數(shù)據(jù)連接超時(shí)時(shí)間90秒
max_clients=1                   # 最大連接數(shù)1
max_per_ip=1                    # 每個(gè)ip最大連接數(shù)1
local_max_rate=25000            # 最大傳輸數(shù)率25000B/s


七.啟動(dòng)服務(wù):
[root@KcentOS5 ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [ OK ]
八.測(cè)試:
1.在虛擬用戶(hù)目錄中預(yù)先放入文件:
[root@KcentOS5 ~]# touch /opt/vsftp/kanecruise/kc.test

2.從其他機(jī)器作為客戶(hù)端登陸FTP:
[root@Yum ~]# ftp
ftp> open 192.168.1.22
Connected to 192.168.1.22.
220 This Vsftp server supports virtual users ^_^
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.1.22:root): kanecruise
331 Please specify the password.
Password: 123456
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

3.測(cè)試列單操作
ftp> ls
227 Entering Passive Mode (192,168,1,22,220,24)
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 15 21:14 kc.test
226 Directory send OK.(目錄列單成功)

4.測(cè)試上傳操作:
ftp> put
(local-file) KC.repo
(remote-file) KC.repo
local: KC.repo remote: KC.repo
227 Entering Passive Mode (192,168,1,22,230,1)
150 Ok to send data.
226 File receive OK. (上傳成功)
699 bytes sent in 0.024 seconds (29 Kbytes/s)
ftp>

5.測(cè)試建立目錄操作:
ftp> mkdir test
257 "/opt/vsftp/kanecruise/test" created (目錄建立成功)

6.測(cè)試下載操作:
ftp> get kc.test
local: kc.test remote: kc.test
227 Entering Passive Mode (192,168,1,22,164,178)
150 Opening BINARY mode data connection for kc.test (0 bytes).
226 File send OK.(下載成功)

7.測(cè)試超時(shí):
ftp> dir
421 Timeout.(超時(shí)有效)
ftp> user
Not connected.注意:
在/etc/vsftpd/vsftpd.conf中,local_enable的選項(xiàng)必須打開(kāi)為Yes,使得虛擬用戶(hù)的訪問(wèn)成為可能,否則會(huì)出現(xiàn)以下現(xiàn)象:
----------------------------------
[root@KcentOS5 ~]# ftp
ftp> open 192.168.1.22
Connected to 192.168.1.22.
500 OOPS: vsftpd: both local and anonymous access disabled!
----------------------------------
原因:虛擬用戶(hù)再豐富,其實(shí)也是基于它們的宿主用戶(hù)overlord的,如果overlord這個(gè)虛擬用戶(hù)的宿主被限制住了,那么虛擬用戶(hù)也將受到限制。
補(bǔ)充:

500 OOPS:錯(cuò)誤

有可能是你的vsftpd.con配置文件中有不能被實(shí)別的命令,還有一種可能是命令的YES 或 NO 后面有空格。

我遇到的是命令后面有空格。因?yàn)槲沂怯肎EDIT來(lái)編輯的配置文件

550 權(quán)限錯(cuò)誤,不能創(chuàng)建目錄和文件

解決方法: 關(guān)閉selinux

# vi /etc/selinux/config

將 SELINUX=XXX -->XXX 代表級(jí)別

改為

SELINUX=disabled

重啟

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI