歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> VSFTPd自架Linux網絡安裝服務器

VSFTPd自架Linux網絡安裝服務器

日期:2017/3/6 15:47:53   编辑:關於Unix
約定: 1。本帖操作環境是Redhat 9.0,vsFTPd的版本是Redhat 9.0所帶的vsftpd-1.1.3-8.i386.rpm,在安裝盤的第三張中 2。vsFTPd實現的最基本的目的:用系統中存在的真實用戶能登入FTP,能用匿名訪問。 3。本帖中vsFTPd運行模式是在standalone模式下運行的,也
  約定:
  1。本帖操作環境是Redhat 9.0,vsFTPd的版本是Redhat 9.0所帶的vsftpd-1.1.3-8.i386.rpm,在安裝盤的第三張中
  
  2。vsFTPd實現的最基本的目的:用系統中存在的真實用戶能登入FTP,能用匿名訪問。
  
  3。本帖中vsFTPd運行模式是在standalone模式下運行的,也就是說,本帖中vsFTPd所有的功能都是在standalone模式下運行的。至於有些功能是否能在xinetd模式下運行,您就得測試了,不能照搬照抄。因為有些功能是必須運行在特定的模式下的。
  
  3。服務器的IP和和DNS設定
  
  第一塊網卡
  IP:192.168.0.1
  子掩碼:255.255.255.0
  網關不設置:
  第二塊網卡:
  IP:192.168.0.2
  子掩碼:255.255.255.0
  網關不設置
  
  因為我的操作環境是一個小型的局域網,所以其它的機器的IP都是在192.168.0這個網段上。ADSL是接在服務器的第一個網卡上。服務器的第二個網卡是接集線器,其它的客戶機都是接在集線器上。為了能讓ADSL訪問internet,因為自己手動設置了IP,所以DNS也要自己來設置,DNS如下:
  
  202.96.134.133
  202.96.168.68
  
  設置工具是:
  [root@linuxsir001 root]# redhat-config-network
  
  相應參考資料:vsFTPd官方文檔:
  
  http://www.linuxsir.com/bbs/showthr...;threadid=43451
  
  一。用vsFTPd來架設FTP服務器,vsFTPd服務器是目前最好的FTP服務器軟件,優點是體積小,可定制強,效率高
  
  1。查看是否安裝了vsFTPd軟件
  [root@linuxsir001 root]# rpm -qa | grep vsftpd
  如果沒有任何顯示,說明沒有把vsFTPd安裝上,如果出現的是下面的這樣的提示,就證明已經安裝上了。
  
  [root@linuxsir001 root]# rpm -qa | grep vsftpd
  vsftpd-1.1.3-8
  
  我以Redhat 9.0,以其自帶的vsFTPd包vsftpd-1.1.3-8版本來為本帖約定。
  
  [root@linuxsir001 root]# rpm -ivh vsftpd*.rpm
  
  2。打開vsFTPd服務器。
  
  [root@linuxsir001 root]# ntsysv
  
  把vsftpd服務器打開,也就是在運行 ntsysv命令後,把vsftpd服務選中。
  
  [*] vsftpd
  
  3。運行/etc/init.d/vsftpd start
  
  [root@linuxsir001 root]# /etc/init.d/vsftpd start
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  4。配制vsFTPd,vsFTPd的運行有兩種模式,一種是standalone "initd"模式,另外一種是xinetd模式,上面我們所說的就是standalone "initd"運行模式。兩種模式運行機制不是相同的,stardard initd模式,適合專業FTP,且FTP總是一直有人訪問,占用資源也是比較大,如果您的FTP總是有人訪問和登入。就要用這種模式。如果您的FTP訪問人數比較小,建議您用xinetd模式。xinetd模式,是當用戶請求時,vsFTPd才會啟動。
  
  不同的環境,當然得用不同的啟動模式。
  
  如果想了解更多的,請在本帖後面跟帖,我會慢慢補充xinetd模式,以及虛擬用戶如何設置方面的問題。
  
  1]我們主要把vsFTPd的配制文件改一下就行了。配制文件在/etc/vsftpd/vsftpd.conf,用您喜歡的編輯器打開。請參考下面的配制文件。
  
  # Example config file /etc/vsftpd.conf
  #
  # The default compiled in settings are very paranoid. This sample file
  # loosens things up a bit, to make the ftp daemon more usable.
  #
  # Allow anonymous FTP?
  anonymous_enable=YES
  #
  # 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
  #
  # 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/vsftpd.log
  #
  # If you want, you can have your log file in standard ftpd xferlog format
  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 turning on ascii_download_enable enables malicious remote parties
  # to consume your I/O resources, by issuing the command "SIZE /big/file" in
  # ASCII mode.
  # These ASCII options are split into upload and download because you may wish
  # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
  # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
  # on the client anyway..
  #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
  
  pam_service_name=vsftpd
  userlist_enable=YES
  #enable for standalone mode
  listen=YES
  tcp_wrappers=YES
  
  2]更改完配制文件後,我們可以用下面的命令來重啟vsFTPd服務器
  
  [root@linuxsir001 root]# /etc/init.d/vsftpd restart
  關閉 vsftpd: [ 確定 ]
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  3]以匿名方式來訪問測試,在text模式下:
  
  注意:在text模式下,要用用戶名ftp,密碼ftp來訪問,這才是在text中匿名訪問FTP。看如下的操作:
  
  [root@linuxsir001 root]# ftp 192.168.0.1
  Connected to 192.168.0.1.
  220 (vsFTPd 1.1.3)
  530 Please login with USER and PASS.
  530 Please login with USER and PASS.
  KERBEROS_V4 rejected as an authentication type
  Name (192.168.0.1:root): ftp 這裡寫上ftp
  331 Please specify the password.
  Password:[這裡添寫ftp的密碼],匿名登入密碼也是ftp
  230 Login suclearcase/" target="_blank" >ccessful. Have fun.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp> ls
  227 Entering Passive Mode (192,168,0,1,137,151)
  150 Here comes the directory listing.
  drwxr-xr-x 6 0 0 4096 May 25 13:54 RedHat90
  drwxr-xr-x 2 0 0 4096 Feb 28 19:21 pub
  226 Directory send OK.
  ftp>
  那匿名用戶所訪問的是哪個目錄?是/var/ftp這個目錄
  
  出現問題的解決:有時出錯,是因為沒有ftp和nobody用戶,所以要在系統中添加這兩個用戶,一般的情況下,這兩個用戶在系統中是存在的。看下面的操作。
  [root@linuxsir001 root]# adduser ftp
  adduser: user ftp exists
  [root@linuxsir001 root]# adduser nobody
  adduser: user nobody exists
  
  從上面的操作中可知ftp和nobody用戶是存在的,所以沒有必要添加ftp和nobody用戶了。如果不存在,一定要添加這兩個用戶,否則會出現匿名用戶不能訪問的情況。
  
  4]如果要以系統中存在的普通用戶登入FTP,也沒有什麼可以設置的,添加一個用戶就行。比如我要添加beinan這個用戶,就要用下面的辦法
  
  [root@linuxsir001 root]# adduser beinan
  [root@linuxsir001 root]# passwd beinan
  Changing password for user beinan.
  New password:
  BAD PASSWORD: it does not contain enough DIFFERENT characters
  Retype new password:
  passwd: all authentication tokens updated successfully.
  [root@linuxsir001 root]#
  
  這樣的話,就在/home目錄中出現一個beinan的用戶目錄:如下:
  
  [root@linuxsir001 root]# ls /home/
  beinan
  
  如果我們想讓beinan這個用戶作為虛擬用戶,也就是說,beinan這個用戶是不能登入系統的,只能是登入FTP。 那這樣的用戶應該如何添加呢??
  
  [root@linuxsir001 backupNow]# adduser -g ftp -s /sbin/nologin beinan
  [root@linuxsir001 backupNow]# passwd beinan
  Changing password for user beinan.
  New password:
  Retype new password:
  passwd: all authentication tokens updated successfully.
  [root@linuxsir001 backupNow]#
  
  注:這僅僅是vsFTPd添加虛擬用戶的一個方法,還有更好的辦法需要我們去學習!另外的辦法也在測試之中。嚴格上來說,這種辦法不能算虛擬用戶。還有另外的一個辦法,就是通過pam認證,用db_load來添加用戶,目前我也弄成功了,不過相對要復雜一點。正在測試之中。
  
  如果我們想把用戶目錄定位到別的目錄應該怎麼辦呢??這個也比較簡單,看一下useradd就比較明白了。比如我想添加beinan這個用戶,並把目錄放在/opt目錄中:如下操作:
  
  [root@linuxsir001 root]# adduser -d /opt/beinan beinan
  [root@linuxsir001 root]# passwd beinan
  Changing password for user beinan.
  New password:
  Retype new password:
  passwd: all authentication tokens updated successfully.
  
  如果是添加虛擬用戶,也就是不讓用戶登入系統,只能登入FTP的用戶。如果我們想把beinan這個用戶目錄定位在/opt/beinan這個目錄中,根據上面的方法。我們應該如下操作
  [root@linuxsir001 backupNow]# adduser -d /opt/beinan -g ftp -s /sbin/nologin beinan
  [root@linuxsir001 backupNow]# passwd beinan
  Changing password for user beinan.
  New password:
  Retype new password:
  passwd: all authentication tokens updated successfully.
  [root@linuxsir001 backupNow]#
  
  看一下是不是已經成功添加到了beinan這個用戶,並把beinan的家目錄放在了/opt目錄中呢??
  
  [root@linuxsir001 root]# ls /opt/
  beinan
  
  證明已經成功。
  
  我們可以在text模式下以beinan用戶登入,然後來訪問ftp。
  
  [root@linuxsir001 root]# ftp 192.168.0.1
  Connected to 192.168.0.1.
  220 (vsFTPd 1.1.3)
  530 Please login with USER and PASS.
  530 Please login with USER and PASS.
  KERBEROS_V4 rejected as an authentication type
  Name (192.168.0.1:root): beinan
  331 Please specify the password.
  Password:
  230 Login successful. Have fun.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp>
  
  是不是成功了???
  
  我們也可以用gftp來訪問beinan用戶,並上傳相應的東西,所傳上的東西就放在beinan用戶所在的家目錄中,普通用戶的家目錄在哪裡,寫您所用的添加用戶的方法有關。我在前面已經說了兩種辦法,一種是默認的添加方法,就是放在/home目錄中。
  
  在本例中,我是采用默認的添加用戶的方法。也就是不特別指定用戶用戶,這樣的話,用戶目錄就在/home目錄中。比如用beinan登入FTP時,訪問的就是/home/beinan這個目錄。讓傳的東西也在這個目錄中。
  
  那匿名用戶所訪問的是哪個目錄呢???
  
  應該是:/var/ftp這個目錄
  
  訪問ftp的幾種方法
  第一種方法就是text訪問,也就是用ftp命令來訪問。這個前面已經說過了。
  
  第二種方法是以客戶端FTP軟件來訪問,在linux中有gftp。在本例中,我的FTP地址是通過局域網訪問的。地址欄中,添上192.168.0.1,端口是21,用戶名和密碼的添寫,如果您是用匿名登入,請不要添寫用戶名和密碼。如果用普通用戶登入,這個是必須要用用戶名和密碼的。
  
  第三種辦法是和浏覽器訪問:如果匿名登入,就直接用下面的方法:
  ftp://192.168.0.1
  如果是用戶登入方式,應該是
  ftp://[email protected]
  
  如果想讓在互聯網上的用戶能訪問到,如果您是用ADSL來訪問互聯網,要查找到您的動態IP,用下面的辦法
  [root@linuxsir001 root]# ifconfig ppp0
  ppp0 Link encap:Point-to-Point Protocol
  inet addr:218.61.7.23 P-t-P:218.61.7.1 Mask:255.255.255.255
  UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
  RX packets:24245 errors:0 dropped:0 overruns:0 frame:0
  TX packets:20411 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:3
  RX bytes:23103297 (22.0 Mb) TX bytes:3588337 (3.4 Mb)
  
  從上面的可以知道,能讓在internet訪問的地址是:218.61.7.23
  
  二。如何讓局域網通過這個FTP安裝Linux呢??以Redhat 9.0為例:
  
  1。我們要在/var/ftp中,為每個發行版建一個目錄,然後把每個發行版的每個版本再建一個目錄。把每個版本的ISO都解壓到相應的目錄裡。舉個例子:
  
  比如我想讓其它的客戶機,通過我的服務器來安裝Redhat9.0,我就要在/var/ftp目錄中建一個RedHat90的目錄,然後把RedHat 9.0的三個ISO都解到這個目錄中。
  
  這樣服務器的設置就完成了。
  
  2。客戶機方面如何引導及設置???我們可以做一個系統的引志盤,但有的發行版也沒有必要。這也要以各個發行版的情況而定。比如Redhat 9.0的安裝,如果您的客戶機上有windows,就直接通過局域網的FTP,dosutils images isolinux三個目錄放到一個在fat32分區中建的目錄中,比如說在客戶機上建一個Redhat9的目錄,然後把三個文件拷到客戶機中的fat32分區中的Redhat9的目錄中。
  
  3.客戶機安裝及操作:
  
  以DOS盤引導,不要加載CDROM,直接進入客戶機中fat32分區Redhat9\dosutils目錄,執行下面的命令。
  
  autoboot
  
  這樣就開始了安裝:
  
  4.出現的畫面中,我們要選ftp安裝。在設置網絡環境時,我們要設置好IP和網關之類的。
  
  以我的局域網為例:
  
  客戶機的IP設置成192.168.0.5,掩碼也是2552555.255.0,網關設置成192.168.0.1。name 服務可以不設置。以匿名方式訪問FTP。
  
  下一步會出現讓我們添寫FTP,及安裝源的地址,還是以我的局域網為例:
  
  地址:192.168.0.1
  路徑:因為我是把三個ISO放在了/var/ftp/RedHat90的目錄下,我應該寫如下的
  
  /RedHat90
  
  這樣就OK了,一切和其它的安裝方式都是一樣的了。
  
  因為每個發行版不太一樣,所以通過網絡安裝,有的要做引導盤,如何做引導盤,我想大家早就知道了。如果不知道這方面的,請用搜索來找這方面的帖子。
  
  ________________
  ===========================
  請弟兄們發帖時要寫個好標題,多謝!
  ===========================
  每天以1000KM/H的速度在跑,感覺還是時間不夠:(
  “西學東漸,洋為中用” + 創造 = ?
  linux ppc
  
  向版主報告此貼 | IP地址: 已記錄
  
  補充一:如何有選擇的把用戶限制在家目錄中呢?
  
  我們要自己建一個文件,在/etc目錄中
  #touch /etc/vsftpd.chroot_list
  以beinan和nanbei這兩個用戶限制在他們所在的家目錄中,而其它的FTP用戶不做此限制。
  
  在vsftpd.chroot_list這個文件中,把beinan和nanbei添上去就行,注意,每個用戶占一行。
  beinan
  nanbei
  然後改/etc/vsftpd/vsftpd.conf文件,找如下的兩行
  
  #chroot_list_enable=YES
  #chroot_list_file=/etc/vsftpd.chroot_list
  
  把前面的#號去掉,也就是這樣的
  chroot_list_enable=YES
  chroot_list_file=/etc/vsftpd.chroot_list
  
  如果沒有這樣的兩行,就可以自己添加上去也是一樣的。
  
  設置好後,重新vsFTPD服務器。
  
  補充一之補充:如何把系統內所有的FTP用戶都限制在家目錄中呢??經juliaugong兄的提示,我查找了vsFTPd的洋文說明,證明這個選項是一刀切的解決所有的用戶都能限制在家目錄中
  
  我們可以通過更改vsftpd.conf文件,加入如下的一行
  
  chroot_local_user=YES
  
  改完配制文件,不要忘記重啟vsFTPd服務器
  
  [root@linuxsir001 root]# /etc/init.d/vsftpd restart
  關閉 vsftpd: [ 確定 ]
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  補充二:打開vsFTP服務器的日志功能:
  
  把下面xferlog_file前面的#號對掉,也就是把vsftp的log功能打開,這樣我們就能在/var/log目錄下查看vsftpd.log。這是vsFTP的日志功能,這對於我們來說是極為重要的。
  #xferlog_file=/var/log/vsftpd.log
  
  補充三:如何讓綁定IP到vsFTP?也就是說,如何讓用戶只能通過某個IP來訪問FTP。其實這個功能很有意思。如果綁定的是內網的IP,外部是沒有辦法訪問的。如果綁定的是對外服務的IP,內網也只能通過對外服務的IP來訪問FTP
  
  在/etc/vsftpd/vsftpd.conf中加一行,以我的局域網為例,請看第一帖中的操作環境,這樣外網就不能訪問我的FTP了,內網也可能通過192.168.0.2來訪問FTP
  listen_address=192.168.0.2
  
  加完後,要重啟vsFTP服務器
  
  [root@linuxsir001 root]# /etc/init.d/vsftpd restart
  關閉 vsftpd: [ 確定 ]
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  補充四:如何讓vsFTP服務器限制鏈接數,以及每個IP最大的鏈接數??
  
  答:應該改vsFTP服務器的配制文件vsftpd.conf,加入下面的兩行:
  
  max_clients=數字
  max_per_ip=數字
  
  舉例:我想讓我的vsFTP最大支持鏈接數為100個,每個IP,最多能支持5個鏈接,所以我應該在vsftpd.conf中加上如下的兩行:
  max_clients=100
  max_per_ip=5
  
  改好了配制文件,不要忘記啟動vsftp服務器。
  
  補充五:如何限制下載的速度?
  
  anon_max_rate=數字 注:這是匿名的下載速度
  local_max_rate=數字 注:這是vsFTP服務器上普通用戶的下載速度
  
  注:這個數字的單位是字節,所以我們要計算一下。比如我想讓匿名用戶和vsFTP上的用戶都以80KB下載,所以這個數字應該是1024x80=81920
  所以我們要在vsftpd.conf中加入下面的兩行
  anon_max_rate=81920
  local_max_rate=81920
  
  不要忘記重啟vsftpd服務
  
  補充六:我的硬盤空間有限,如何把帳號ftp默認的路徑/var/ftp更改到別處?或者是,我的linux所有的目錄都放在/根分區,因為空間緊張,我能否把ftp這個用戶的默認路徑放到別的分區??
  
  可以,應該如下操作!
  
  首先要把ftp這個用戶刪除
  #userdel -r ftp
  會有錯誤信息,不過不用理,這是正常的。
  
  然後我們再把這個用戶添加上,比如我想為帳號ftp的家目錄設置在/mnt/LinG/ftp,我們就可以如下操作
  
  [root@linuxsir001 root]# mkdir /mnt/LinG
  
  [root@linuxsir001 root]# adduser -d /mnt/LinG/ftp -g ftp -s /sbin/nologin ftp
  
  僅僅是這樣做還不行,因為這樣還是不能讓匿名用戶找到它的家目錄,所以我們必須改變/mnt/LinG/ftp這個目錄的權限。
  
  [root@linuxsir001 root]# chmod 755 /mnt/LinG/ftp/
  
  [root@linuxsir001 root]# chown -R root.root /mnt/LinG/ftp/
  
  補充七:如何定制歡迎信息,也就是我們登入有些FTP之後,會出現類似:歡迎您來到LinuxSir FTP,在這裡,您會得到最真誠的幫助,如果有什麼問題和建議,請來信,多謝。
  實現這個並不難,我們可以查看vsftpd.cof文件中,是否有這行。
  dirmessage_enable=YES
  如果沒有就加上,如果dirmessage_enable=YES前面有#號,就把#號去掉。
  
  然後我們制定一個.message文件,寫上您想要寫的東西,比如是.message的內容是如下的:
  
  歡迎您來到LinuxSir FTP!
  在這裡,您會得到最真誠的幫助;
  如果有什麼問題和建議,請來信,多謝。
  
  我們可以用編輯器來寫這個.message,我想這個過程就不用說了吧。
  
  然後我們把.message這個文件復制到各個用戶的家目錄中。比如我的FTP的一個用戶是beinan,這個用戶所在的家目錄是/home/beinan
  我們就要把.message放在/home/beinan這個目錄下。如果系統用戶ftp,他的目錄就是/var/ftp這個目錄,這個是默認的,當匿名用戶登入時就訪問的是/var/ftp這個目錄。我們要讓匿名用戶能看到歡迎信息。就要把.message放在/var/ftp目錄中。其它的用戶,也無非就是類似的操作。
  
  補充八:如何實現虛擬路徑?
  比如:
  /home/a 映射為ftp://localhost/a
  /home/b/c 則為ftp://localhost/c
  
  其實這個不能說是vsFTPd的內容,其實我們早就接觸過了,可能我們沒有注意,我們可以通過如下的方法來實現。
  
  #mount --bind [原有的目錄] [新目錄]
  
  比如我的ftp的默認目錄是/var/ftp,我想把/mnt/LinG/WinSoft文件夾,映射到/var/ftp目錄中,我就如下操作
  
  我們要先在/var/ftp目錄中建一個目錄
  #mkdir /var/ftp/WinSoft
  然後執行mount命令
  #mount --bind /mnt/LinG/WinSoft /var/ftp/WinSoft
  
  這樣就OK了。
  
  補充九:如何上匿名訪問、上傳,並支持下載和執行?
  
  在默認的情況下,vsftp是不支持匿名用戶的訪問的,所以我們要自己打開相應的選項。現在我針對這個問題,我們要打開如下的選項。
  
  anonymous_enable=YES 注:允許匿名訪問
  anon_upload_enable=YES 注:允許上傳
  anon_mkdir_write_enable=YES 注:允許建立相應的目錄
  anon_umask=022 把上傳到FTP的文件或者目錄改變權限
  
  當然打開這些選項還是不行的,我們還要讓匿名寫入文件的上一級目錄有寫入權,以我所做的FTP為例,我所做的FTP的匿名訪問的目錄是/var/ftp,在vsFTPd中,/var/ftp這個目錄是不能讓匿名用戶有寫入權限的,這是為了安全考慮,所以我們必須自己在/var/ftp目錄中建一個目錄,讓這個目錄有寫入權。
  
  比如:我在/var/ftp目錄建一個upload目錄,然後把它的權限設置成777,這樣匿名用戶就能寫入了。
  
  #mkdir /var/ftp/upload
  #chmod 777 /var/ftp/upload
  
  改了一系列的文件,不要忘記重啟vsFTPd服務器
  
  我是用standalone模式的,當然用下面的方法
  
  [root@linuxsir001 root]# service vsftpd restart
  關閉 vsftpd: [ 確定 ]
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  如果您用的是xinetd模式來啟動vsFTPd,我們要重啟xinetd服務器
  [root@linuxsir001 root]# service xinetd restart
  停止 xinetd: [ 確定 ]
  啟動 xinetd: [ 確定 ]
  [root@linuxsir001 root]# ]
  
  補充十:通過pam認證方式,添加虛擬用戶
  
  通過pam認證,用db_load添加用戶,是真正的虛擬用戶。現在我們簡單的介紹一下,通過以後的學習,我們再深入補充:
  
  1。在/etc/pam.d/目錄中創建一個文件ftp
  [root@linuxsir001 root]# touch /etc/pam.d/ftp
  
  2。在/etc/pam.d/ftp裡面加上如下的兩行
  auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
  account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
  
  3。創建一系統的用戶名用密碼的文件logins.txt
  [root@linuxsir001 root]# touch logins.txt
  在logins.txt文件中,輸入如下的內容。這個內容您可以自己來定。比如我下面的。其實linuxsir007是FTP的虛擬用戶名,123456是linuxsir007的密碼;linuxsir008是虛擬用戶名,234567是linuxsir008的密碼,以此類推,您想加入幾個就是幾個;下面是我添加的FTP的虛擬用戶名和密碼。
  linuxsir007
  123456
  linuxsir008
  234567
  linuxsir009
  567890
  linuxsir010
  678901
  linuxsir011
  789012
  
  4。創建一個真實的用戶名linuxsir006,這個linuxsir006的用戶,所在的家目錄由您來定。我在這裡不多說了。我是按系統默認的來添加的。
  
  [root@linuxsir001 root]# useradd linuxsir006
  
  5。把/etc/hosts復制到/home/linuxsir006,並改變它的屬主
  
  [root@linuxsir001 root]#cp /etc/hosts /home/linuxsir006/hosts
  
  [root@linuxsir001 root]#chown linuxsir006.linuxsir006 /home/linuxsir006/hosts
  
  6。通過db_load來創建虛擬用戶的庫文件。我們在前面建的logins.txt文件,我是放在了/root用戶目錄下。所以咱們得把目錄切換到/root目錄來創建虛擬用戶的庫文件。
  
  [root@linuxsir001 root]# db_load -T -t hash -f logins.txt /etc/vsftpd_login.db
  
  7。更改vsftpd.conf文件,加入如下的幾行
  pam_service_name=ftp
  guest_enable=YES
  guest_username=linuxsir006
  anon_world_readable_only=NO
  
  8。重啟vsFTPd服務器;改了一系列的文件,不要忘記重啟vsFTPd服務器
  
  我是用standalone模式的,當然用下面的方法
  
  [root@linuxsir001 root]# service vsftpd restart
  關閉 vsftpd: [ 確定 ]
  為 vsftpd 啟動 vsftpd: [ 確定 ]
  [root@linuxsir001 root]#
  
  如果您用的是xinetd模式來啟動vsFTPd,我們要重啟xinetd服務器
  [root@linuxsir001 root]# service xinetd restart
  停止 xinetd: [ 確定 ]
  啟動 xinetd: [ 確定 ]
  [root@linuxsir001 root]#
  
  9。如果您想讓用戶登入FTP時,登入成功的相應的信息,請把您制作的.message復制到您的用戶的家目錄中,這方面的請參考前面的補充。
  
  10。測試:
  [root@linuxsir001 root]# ftp 192.168.0.1
  Connected to 192.168.0.1.
  220 (vsFTPd 1.1.3)
  530 Please login with USER and PASS.
  530 Please login with USER and PASS.
  KERBEROS_V4 rejected as an authentication type
  Name (192.168.0.1:root): linuxsir007
  331 Please specify the password.
  Password:
  230-歡迎光臨LinuxSir自由FTP
  230-在這裡,您將得到最真誠的幫助!
  230-本站限度為30KB!
  230-每個IP限四個線程
  230-請大家遵守FTP的有關規定。
  230-多謝合作!
  230-
  230-LinuxSir管理部
  230 Login successful. Have fun.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp> ls
  227 Entering Passive Mode (192,168,0,1,85,171)
  150 Here comes the directory listing.
  -rw-r--r-- 1 ftp ftp 174 Jun 01 12:59 hosts
  drwxr-xr-x 3 ftp ftp 4096 Jun 01 13:29 linuxsir008
  drwxr-xr-x 2 ftp ftp 4096 Jun 01 13:24 sun
  226 Directory send OK.
  ftp>
  
  補充十一:如何把Redhat 9.0中系統默認安裝的vsftpd-1.1.3-8.i386.rpm,系統默認vsFTPd是用standalone啟動方式 ,改為xinetd啟動方式 ?
  如果是用源碼包安裝的,安裝後就是xinetd模式,如果是用RPM包安裝的,在Redhat 9.0中,應該用下面的方法來解決。
  
  1.在/etc/xinetd.d/目錄中創建一個文件vsftpd
  
  [root@linuxsir001 root]# touch /etc/xinetd.d/vsftpd
  
  /etc/xinetd.d/vsftpd內容如下:
  
  service ftp
  {
  socket_type = stream
  wait = no
  user = root
  server = /usr/sbin/vsftpd
  # server_args =
  # log_on_success += DURATION USERID
  # log_on_failure += USERID
  nice = 10
  disable = no
  }
  
  2。復制vsftpd.conf到/etc/目錄下,因為xinetd對vsFTPd配制文件應該在/etc目錄下,所以我們就必須把這個文件復制到/etc目錄下,否則會出現系統中local用戶無法登入,也就是說,不復制這個文件會出現ftp非匿名用戶無法訪問,只能用匿名用戶訪問。
  
  [root@linuxsir001 root]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd.conf
  
  3。更改配制文件/etc/vsftpd.conf,把如下的項注掉:
  也就是把
  listen=YES
  改為
  #listen=YES
  或者是把這行刪除也行。
  
  4。把/etc/init.d/vsftpd這個文件刪除。其實最好的備份到別處,因為我們有時實驗來實驗去,可能還會轉到standalone模式啟動。我就直接移動到別的目錄,比如是/root下面的backup目錄。
  
  [root@linuxsir001 root]#mkdir /root/backup
  [root@linuxsir001 root]# mv /etc/init.d/vsftpd /root/backup
  
  5。運行ntsysv,把vsftpd的服務取消
  
  [root@linuxsir001 root]#ntsysv
  
  [ ] vsftpd
  
  6。重啟xinetd服務
  
  [root@linuxsir001 root]# service xinetd restart

Copyright © Linux教程網 All Rights Reserved