Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux 伺服器

在 Linux 上架設 WU-FTP:從安裝、組成到權限細節

在眾多網路服務裡,FTP 的地位一直很關鍵。網路上大量軟體資源都存放在 FTP 主機上,可以說 FTP 與 Web 服務合起來就撐起了 Internet 應用的絕大部分。

依服務對象不同,FTP 大致分成兩類:一是系統型 FTP,只允許機器上具備帳號的合法使用者登入;二是匿名 FTP(Anonymous FTP),任何人都能連上來抓檔案。

挑一套 FTP 伺服器軟體

如果你在安裝 Linux 時勾選了 ftpd,系統其實已經幫你裝好一個預設的 FTP 服務,接下來只要依需求微調設定即可。

多數發行版採用的是 Washington University FTP,一般簡稱 wu-ftp。它是相當知名的 FTP 伺服器軟體,可運行於 IBM AIX、FreeBSD、HP-UX、NeXTstep、Dynix、SunOS、Solaris 等眾多 UNIX 平台,網路上的 FTP 主機有一大半以上都在用它。它適合吞吐量大的場景,主要能力包括:下載時自動壓縮或解壓縮、依來源網路設定不同的存取限制、記錄上傳與下載時間、即時顯示傳輸資訊、以及限制最大連線數以控制負載。

wu-ftp 的組成

裝好之後,/bin 底下會多出五個可執行檔:ftpd(伺服器主程式)、ftpshut(關閉服務)、ftpcount(線上人數)、ftpwho(連線狀況)、ckconfig(檢查設定是否正確)。

另外在 /etc 與 /var 下會產生七個設定檔:/etc/ftpusers、/etc/ftpaccess、/var/run/ftp.pids、/etc/ftpconversions、/var/log/xferlog、/etc/ftpgroups、/etc/ftphosts。

系統還會建立一個名為 ftp 的特殊帳號,並在 /home 下產生 ftpd 目錄,匿名登入時就是落在這裡。其中的子目錄各有分工:/home/ftpd/bin 放使用者可用的執行檔、/home/ftpd/etc 放設定檔、/home/ftpd/pub 放供下載的內容、/home/ftpd/incoming 則是上傳區。

設定要點

確認 inetd.conf

inetd 是 Linux 的超級伺服器,同時監聽多個 TCP/IP 埠,收到請求才派生對應服務,因而省下不少資源。wu-ftp 正是靠它監聽,所以設定檔裡必須有這一行:

ftp stream tcp nowait root /usr/sbin/tcpd wu.ftpd

可以用 cat /etc/inetd.conf | grep ftp 確認,沒有的話手動補上。

wu-ftpd 的常用參數

-d 出錯時寫入 syslog;-l 記錄每次連線;-t 設定閒置幾分鐘後斷線;-a 採用 /etc/ftpaccess 設定;-A 不採用;-L 記錄連線後執行的命令;-I 記錄上傳;-o 記錄下載。綜合來看,建議把預設那行改成:

ftp stream tcp nowait root /usr/sbin/tcpd wu.ftpd –a –I

啟用自動壓縮

想讓伺服器具備自動壓縮/解壓縮能力,得先把 tar、gzip、gunzip、compress、uncompress 等命令複製到 /home/ftpd/bin。

/etc/ftpaccess

這是最關鍵的設定檔,權限與行為幾乎都在這裡決定。一個典型範例:

loginfails 3
class local real *
class remote anonymous guest *
limit remote 100 Any /etc/ftpd/toomany.msg
message /etc/ftpd/welcome.msg login
compress yes local remote
tar yes local remote
private yes
passwd-check rfc822 warn
log commands real
log transfer anonymous guest inbound outbound
log transfer real inbound
shutdown /etc/ftpd/shut.msg
delete no anonymous,guest
overwrite no anonymous,guest
rename no anonymous
chmod no anonymous,guest
umask no anonymous
upload /home/ftpd * no
upload /home/ftpd /bin no
upload /home/ftpd /etc no
upload /home/ftpd /pub yes real 0644 dirs
upload /home/ftpd /incoming yes real guest anonymous 0644 dirs
alias in /incoming
email guest@xxx.net
email guest@yyy.net
deny *.com.tw /etc/ftpd/deny.msg

Copyright © Linux教程網 All Rights Reserved