1 / 20

FTP Server 架設 (使用 Proftpd)

FTP Server 架設 (使用 Proftpd). Kenduest ( 小州). mailto:kenduest@cynix.com.tw. FTP 服務. 什麼是 FTP FTP 是 File Transfer Protocol 的簡稱。一般我們 稱呼提供 FTP 服務的程式為 FTP Daemon。 提供 FTP 的主機就稱呼為 FTP Server。 Internet 上提供許多檔案可以下載 ( DownLoad), 專門提供檔案下載服務的站台就是 FTP Server。

kerri
Download Presentation

FTP Server 架設 (使用 Proftpd)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FTP Server 架設(使用Proftpd) Kenduest (小州) mailto:kenduest@cynix.com.tw

  2. FTP 服務 • 什麼是 FTP • FTP 是 File Transfer Protocol的簡稱。一般我們 稱呼提供 FTP 服務的程式為 FTP Daemon。提供 FTP 的主機就稱呼為 FTP Server。 • Internet 上提供許多檔案可以下載 (DownLoad), 專門提供檔案下載服務的站台就是 FTP Server。 • 連線到 FTP 主機可以把檔案 DownLoad 回來的 Client 程式稱呼為 Ftp Client。 • UNIX 上常見的 FTPD 常見像是 wu-ftpd 。 • FTP Client,比方單純的 ftp 程式,Unix 系統下 增強型的 Ncftp。Windows 下的 cuteftp 等等。

  3. 使用 Proftp 來架設 FTP • 為何要使用 proftpd ? • proftpd 為 The Professional FTP Daemon 的縮寫簡稱。 • Unix 常見使用的 ftpd 為 wu-ftpd,該程式悠久許多 人使用。一般 Linux Distribution 內建都提供 wu-ftpd 套件來作為 FTP Server。 • wu-ftpd 曾傳出重大的安全性漏洞,另外設定檔案 某方面不夠彈性,某些需求不好設定。 • proftpd 設定檔案方式採用 Apache 設定檔案架構, 設定方便,容易上手,相關權限控管簡單。

  4. 安裝 Proftp 套件程式 • DownLoad: • SRPMS 版本: ftp://ftp.proftpd.org/distrib/packages/SRPMS/proftpd-1.2.1-2.src.rpm Tarball 版本: ftp://ftp.proftpd.org/distrib/source/proftpd-1.2.1.tar.bz2 • Compile and Install: • SRPMS 版本: # rpm --rebuild proftpd-1.2.1-2.src.rpm # cd /usr/src/redhat/RPMS/i386/ # rpm -ihv proftpd-1.2.1-2.i386.rpm

  5. 安裝 Proftp 套件程式 (續) • Compile and Install: • Tarball 版本: # bzip2 -cd /proftpd-1.2.1.tar.bz2 | tar xvf - # cd proftpd-1.2.1 # ./configure --prefix=/usr/local/proftpd --sysconfdir=/etc \ --localstatedir=/var/run \ --with-modules=mod_linuxprivs:mod_ratio: mod_readme:mod_wrap:mod_quota \ --enable-autoshadow # make # make install

  6. 檔案清單內容說明 • 相關檔案: • proftpd 設定檔案 proftpd.conf。RPM 安裝是放置在 /etc 目錄內。自行編譯安裝,有指定 sysconfdir 參數的話,則放置在該指定目錄內,要不然就是 prefix 指定所在的 etc 目錄內。 • 主要執行檔案為 proftpd 。RPM 安裝在 /usr/sbin。 自行安裝,則是在 prefix 指定所在的 sbin 目錄 • 注意事項: • 某些使用 RPM 打包的舊版本,使用 rpm 配合 --rebuild 會產生 proftpd-core、proftpd-standalone、 proftpd-inetd 三個檔案。後者請選擇安裝其中之一。

  7. Proftpd 的啟動 • 使用 standalone 啟動方式: • 確認 proftpd.conf 檔案內的 ServerType 項目內是使用 standalone。比方: ServerType standalone 另外 User 與 Group 都指定為 FTP 。 User nobody Group nobody • 自己編譯安裝的部分,執行 /usr/sbin/proftpd 即可常駐。 使用 RPM 版本的話,可以使用: /etc/rc.d/init.d/proftpd start 啟動。

  8. Proftpd 的啟動 • 使用 inetd 啟動方式: • 確認 proftpd.conf 檔案內的 ServerType 項目內是使用 standalone。比方: ServerType inetd • /etc/inetd.conf 檔案內需要包含: (兩個方式) (1) ftp stream tcp nowait root /usr/sbin/proftpd proftpd (2) ftp stream tcp nowait root /usr/sbin/tcpd proftpd • 另外 User 與 Group 都指定為 nobody 。 User nobody Group nobody • 都改好後,然後執行 /etc/rc.d/init.d/inet restart 重新啟動 inetd 即可生效。(請順便參閱後面注意事項)

  9. Proftpd 的啟動 • 其他事項: • 若是系統有安裝 wu-ftpd,請記得先移除 wu-ftpd 與 anonftp 這兩個套件程式。 • 在 RedHat 7.0 or Mandrake 7.2 版本改用 xinetd 取代 inetd,所以若是要使用 inetd 啟動方式,需要在 /etc/xinetd.d 目錄內加入 proftpd 檔案,內容為啟動 proftpd 的敘述 (參考後頁)。改完後,使用 /etc/rc.d/init.d/xinetd reload

  10. Proftpd 的啟動 (for xinetd) service ftp { disable = no socket_type = stream wait = no user = root server = /usr/sbin/proftpd server_args = proftpd log_on_success += DURATION USERID log_on_failure += USERID nice = 10 }

  11. Proftpd 的設定檔參數 • ServerName : 指定登入 FTP 主機要顯示的訊息 • ServerName “Welcome to My FTP Server” • ServerType : 指定啟動型態。standalone | inetd • ServerType standalone • Port : 指定 standalone 啟動時要監聽哪個 port • Port 21 • umask : 指定建立檔案目錄時,使用的 umask 值 • umask 022 • MaxInstances : 指定 standalone 啟動時,最多啟動服務數量 • MaxInstances 20 • User/Group : 指定啟動時切換的身份與群組 • User nobody • Group nobody

  12. Proftpd 的設定檔參數 • 除了前面整體參數設定之外,主要區分是: • 一般目錄權限的控管 (針對一般使用者) • 匿名登入權限的控管 (針對 anonftp or ftp 使用者) • proftpd.conf 設定方式與 apache 的 httpd.conf 類似, 往後設定會針對 <Directory> ... </Directory> 區段設定 • 匿名使用者部分,則都是規範在: <Anonymous anonymous-path> ... </Anonymous> 區段內 • 一般 ftpd 都會檢查登入使用者所使用的 shell 是否有登記 在 /etc/shells 檔案內。因為系統的 /etc/passwd 檔案內的 ftp 匿名使用者的 shell 程式是空的,會造成登入失敗。所以 匿名區段補上: AnonRequirePassword off RequireValidShell off

  13. Proftpd 的設定檔參數 (進階) • MaxClientsPerHost : 設定單一 host 最多連線次數 • MaxClientsPerHost 5 • MaxLoginAttempts : 設定連線端嘗試登入失敗後幾次斷線 • MaxLoginAttempts 3 • RateReadBPS : 設定每秒下載傳輸速度,bytes 為單位 • RateReadBPS 10240 • 可以放置於 </Directory path> ... </Directory> 限制 • RateWriteBPS : 設定每秒上傳傳輸速度,bytes 為單位 • RateWriteBPS 10240 • 可以放置於 </Directory path> ... </Directory> 限制 • RequireValidShell : 檢查使用者 shell 程式是否合法 RequireValidShell on

  14. Proftpd 的設定檔參數 (進階) • RootLogin : 設定是否可以使用 root 帳號登入 • RootLogin off • DisplayLogin : 設定登入 ftp 主機時,要顯示的內容 • DisPlayLogin welcome.msg • 僅適用於 anonymous 登入與 VirtualHost 使用 • DisplayFirstChdir : 設定切換目錄時,顯示該檔案內容 • DisplayFirstChdir .message • 僅適用於 anonymous 登入與 VirtualHost 使用 • DisplayQuit : 設定結束連線時要顯示的檔案內容 • DisplayQuit saybyebye.msg • 僅適用於 anonymous 登入與 VirtualHost 使用

  15. Proftpd 的設定檔參數 (進階) • TimeoutLogin : 指定連線後多久沒有登入就斷線(秒) • timeoutLogin 100 • TimeoutIdle : 設定登入主機後閒置多久後就斷線 (秒) • TimeoutIdle : 600 • TimeoutNoTransfer : 傳資料過程無回應就斷線時間 (秒) • timeooutNoTransfer 300 • AllowOverwrite : 指定是否可以覆寫原先的檔案 • AllowOverwrte on • 預設是 off。可以適用於整體設定與目錄區段設定 • UseHostsAllowFile : 指定允許連線的主機 • UseHostsDenyFile : 指定拒絕服務的連線主機 • 都是指定檔案,與 /etc/hosts.{allow,deny} 語法一樣

  16. Proftpd 的設定檔參數 (進階) • Class : 定義一個 class 類別 • 語法: Class “name” limit | regex | ip • Class local limit 100 Class default limit 10 Class local regex .*foo.com Class local ip 172.16.1.0/24 • 需要搭配 Classes on 時才有效 • DefaultRoot : 定義登入之後指定某個目錄為 / 根目錄 • 語法: DefaultRoot directory [group-expression] • 預設是 DefaultRoot / • 要限制每個使用者登入都是在家目錄,可以使用 DefaultRoot ~

  17. Proftpd 的設定檔參數 (進階) • <Directory path> ... </Directory> :指定單一目錄的權限設定 • 存取限制,配合 <LIMIT> ... </LIMIT> 規範 • <LIMIT xxxx> ... </LIMIT> : 限制相關 FTP 動作 • 該項目需要使用在 <Directory> .. </Directory> 內 • xxx 可以區分: CWD (Change Working Directory)、 MKD (MaKe Directory) RNFR (ReName FRom), RNTO (ReName TO)、 DELE (DELEte)、RMD (ReMove Directory)、 RETR (RETRieve)、STOR (STORe)、 READ (RETR, STAT)、 WRITE (also include MKD and RMD)、DIRS、 ALL (identical to READ WRITE DIRS)、LOGIN

  18. Proftpd 的設定檔參數 (進階) • <LIMIT xxxx> ... </LIMIT> : 限制相關 FTP 動作 (續) • 配合 Allow 與 Deny 的使用 Allow ["from"] "all"|"none"|host|network[,host|network[,...]] Deny ["from"] "all"|"none"|host|network[,host|network[,...]] Order allow,deny|deny,allow • 使用範例: <Directory /path> <Limit LOGIN> Order Allow,Deny Allow from 128.44.26.,128.44.26. Allow From myhost.mydomain.com Deny from all</Limit> </Directory>

  19. 相關程式與設定檔案 • ftpusers : 限制無法登入的使用者 id • 加入在該檔案內的使用者 id 將會被拒絕無法登入 • 該檔案在編譯指定 prefix 內的 etc 目錄,或者是 /etc • ftpshut : 關閉 ftp 服務 • 暫時不要提供新進來的 ftp 連線,可以執行該程式 • ftpcount : 得知目前連線數量 • 或者是使用 ps auxw | grep “proftpd” 觀察 • xferlog : 為 ftp 傳輸的 log 紀錄 • 該檔案一般放置在 /var/log 目錄內,可以使用 TransferLog 參數指定 • 預設格式: %h %l %u %t \"%r\" %s %b

  20. 上傳設定 • 匿名區域開放上傳方式: <Anonymous> <Directory upload/> <Limit STOR CWD MKD> AllowAll </Limit> <Limit READ RMD DELE> DenyAll </Limit> </Directory> </Anonymous>

More Related