Alanjy-Huang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # ftp server [TOC] ## FTP ### history + 1971年4月16日由 Abhay Bhushan 編寫作為 RFC 114 發布。 + 1980 年,FTP 才在 TCP/IP 的前身 NCP 上執行。該協定先被 TCP/IP 版本,RFC 765(1980年6月)取代, + 1985 年 10 月後來又被 RFC 959 所取代,這也是當前規範。RFC 959 提出了若干標準修改,例如 RFC 1579(1994年2月)使 FTP 能夠穿越NAT與防火牆(被動模式),RFC 2228(1997年6月)提出安全擴充,RFC 2428(1998年9月)增加了對 IPv6 的支援,並定義了一種新型的被動模式 ![](https://i.imgur.com/i4TyTJX.png) ![](https://i.imgur.com/R2CQvbQ.png) >[圖自](https://www.geeksforgeeks.org/file-transfer-protocol-ftp-in-application-layer/) + FTP 主要是應用於檔案傳輸使用,將共享檔案存放於 FTP 伺服器,讓一般使用者可以透過網路來下載或上傳。它的重點是在異質性電腦之間、以及遠距離的檔案共享使用 ### Active模式 + Port mode + 由服務器主動發起傳送資料請求 + ![](https://i.imgur.com/8DrdwYM.png) + ![](https://i.imgur.com/cSPvYFn.png) 1. Client 端主動向 Server 端發送連線需求( SYN ) + 隨機選取一個大於 1024 以上的 port 來主動的連線到 FTP 主機提供的 FTP 埠口 (通常是21) 2. Server 端接受後,回應給 Client 端 (SYN & ACK) 3. Client 端回應確認封包 (ACK) + 完成三項交握 4. Client 端發送資料傳輸要求的命令給 Server + 注意這裡是用命令的通道發送命令 + 告訴 Server 說:『我已經準備好一個資料傳輸的埠口了,請準備進行傳輸吧』 5. Server 端以 ftp-data 埠口主動連線到 Client + Server 用自己的port(通常是20) 主動去連線到剛剛client告知的port + Server 端主動向 Client 端的連線(SYN) 6. Client 端回應主機端,並繼續完成三向交握(ACK) :::info # TCP header ![](https://i.imgur.com/hJDZm55.png) + Control bit + SYN: 1 為希望與對方線進行同步處理(建立連線) + ACK: 1 為回應封包 + FIN: 1 為通知對方結束連線(等對方確認)。 ::: + **BUT 很多在防火牆內的 client 不被允許開啟某個 Port 給他人連線** + 許多機器設置在防火牆內,在防火牆內的機器只能透過防火牆有開啟的 Port 與外部連線,在 active mode 下這些機器就不能主動開啟某個 Port 給 Server 連線 ### passive 被動模式 + 服務器被動等待client!! + ![](https://i.imgur.com/NeH8UuB.png) + ![](https://i.imgur.com/6J8OhCp.png) 1. ~3 如active 一樣的三項交握 4. Client 端發送資料傳輸要求的命令給 Server + 告訴 FTP Server 說『我要使用 PASV 模式(就是 passive 啦!)的方式來進行資料傳輸』 5. Server 端挑選 > 1024 的埠口等待連線 + 在接受 client 的 PASV 要求之後,如果沒有特別的設定時 (目前的 FTP 伺服器版本已經可以指定 passive port 來規定被動式連接的埠口號碼 ) ,Server 會隨機選取一個大於 1024 的埠口 + 由命令通道告訴 client 端說:『我已經開了一個 ftp-data 的埠口等妳連線喔!』 6. Client 端主動向 Server 端建立連線並繼續完成三向交握 :::info ### 自我檢測 + FTP 在 Client 與 Server 進行連線時,主要使用到的 port 有幾個?分別具有什麼用途? + Client 與 Server 進行 FTP 連線時,其模式分為 Active 與 Passive ,這兩種模式的差異為何? + 當 FTP 架設在防火牆內部時,則這個 FTP 需要使用的連線模式為何? + 如果希望防火牆支援FTP,需要下什麼指令 ::: ## proftpd `sudo apt install proftpd` ### proftpd.conf + ServerType:可以設為 inetd 與 standlone 其中之一。 + standalone持續運作在伺服器內,inetd不持續運作 :::info ## inetd + Inetd(internet service daemon) + 只有當其他人對他發出 request 才會運作,因此不需持續地執行它。 ::: + TimeoutNoTransfer + 沒有傳輸的狀況下等多久會 time out + modules.conf:存放啟用的module看看 + ![](https://i.imgur.com/lETAk9X.png) + TLS + SQL + LDAP :::info ### LADAP + **L**ightweight **D**irectory **A**ccess **P**rotocol + 開放中立的工業標準的應用協定,通過IP協定提供存取控制和維護分散式資訊的目錄資訊 + ![](https://i.imgur.com/BOLAJYk.png) ::: + AllowOverwrite:允許覆寫已存在的檔案。 + DenyFilter:指定 FTP 指令裡禁止使用的字串,格式為常規表示式。第 13 行的設定 \*.*/ 禁止了萬用字元。 + Port:指定伺服器使用的通訊埠,21 是 FTP 的標準通訊埠。如果把 Port 設為 0,表示關閉伺服器。 + Umask: 設定預設上傳檔案權限遮罩 + Anonymous(匿名登入): + 泛指不用帳號密碼就可以登入的模式,就可以開匿名者權限,任何人都可以用這個權限登入 + 當使用 ftp client ( 如filezilla) 不打帳密時,就會自動幫你填入 Anonymous 的帳密 + Default + User: anonymous + Password: anonymous@domain.com + User, Group:指定 ProFTPd 伺服器執行所使用的帳號與群組。第 16, 17 行設為作業系統裡權限最低的 nobody, nogroup。 + MaxInstances:指定伺服器可產生子行程的最大值。雖然它不等於,但會影響到可同時連線客戶端的最大數目。 + <Anonymous ~ftp> </Anonymous> 設定匿名登入的相關設定 + ![](https://i.imgur.com/XvmCdc3.png) + User, Group:指定匿名伺服器執行時的帳號與群組身份。使用者在存取時,會套用成這裡指定的帳號與群組所具備的權限。 ### log + `/var/log/proftpd/` + ![](https://i.imgur.com/4GoKOCP.png) :::info ## 加密方式 ### TLS + 啟用TLS 加密變成ftps + ![](https://i.imgur.com/kDNt6QF.png) ### ssh + 利用local tunnel 的方式將管理的通道加密 > [ProFTPD: Configuring FTP over SSH](http://www.proftpd.org/docs/howto/SSH.html) ::: ## ftp vs ftps vs sftp + FTP (File Transfer Protocol) + 明文傳輸 + 使用 21 port 作為命令通道,讓主從雙方先握手建立連線 ACK x SYN 驗證,再依照是否啟用被動模式與否決定是否傳送 PASV 或指定 port 來確認資料傳輸 port (通常是 20),接著就開始進行 STOR 下載檔案或RETR傳送檔案,最後使用 FIN 結束連接(以上的通訊內容全部都是明文喔)。 + FTPS (FTP over SSL/TLS) + 加密內文後傳輸 + 透過安全通訊端層 (SSL) 或傳輸層安全 (TLS) 通訊協定,讓檔案傳輸受到加密保護,減少不必要風險。 :::info ### TLS + Transport Layer Security + SSL 的後繼協議 + 1999 年 IETF 將 SSL 標準化,時改名為 TLS, 而 TLS 1.0 也支援相容 SSL 3.0 的功能 + TLS handshake + 在 TCP 三向交握後進行 + 指定它們將使用的 TLS 版本(TLS 1.0、1.2、1.3等) + 決定它們將使用的密碼套件 + 通過伺服器的公開密鑰和 SSL 憑證頒發機構的電子簽名驗證伺服器的身份 + 生成工作階段金鑰,以便在握手完成後使用對稱加密 ::: + SFTP(SSH File Transfer Protocol) SSH Protocol standard + 加密傳輸管道 + 透過 Secure Shell(SSH)通訊協定傳輸,是SSH 內建的檔案傳輸服務 + 預設 port 22 :::info ### 答案 + FTP 在 Client 與 Server 進行連線時,主要使用到的 port 有幾個?分別具有什麼用途? + 4 個,兩個命令通道 兩個資料通道 + Client 與 Server 進行 FTP 連線時,其模式分為 Active 與 Passive ,這兩種模式的差異為何? + Active 由 client 開啟 port 讓 server 主動發起連線 + passive 由 server 開啟 port 讓 server 被動等待連線 + 當 FTP 架設在防火牆內部時,則這個 FTP 需要使用的連線模式為何? + Passive + 如果希望防火牆支援FTP,需要下什麼指令 + `iptables -A INPUT -p tcp --dport 21 -j ACCEPT` + `iptables -A INPUT -p tcp --dport 20 -j ACCEPT` + `iptables -A OUTPUT -p tcp --sport 21 -j ACCEPT` + `iptables -A OUTPUT -p tcp --sport 20 -j ACCEPT` ::: ## REF [資料傳輸安全ithome](https://ithelp.ithome.com.tw/articles/10188645) [SFTP FTP ](https://www.xuehua.us/a/5eb6168b86ec4d433b2dba31?lang=zh-tw) [FTP](https://www.baeldung.com/cs/active-vs-passive-ftp) [FTP in application layer](https://www.geeksforgeeks.org/file-transfer-protocol-ftp-in-application-layer/) [ProFTPD: Configuring FTP over SSH](http://www.proftpd.org/docs/howto/SSH.html) [ProFTPD config](https://yungyuc.github.io/oldtech/debian/ProFTPdConf.html#id1) [Proftpd other setting](https://datahunter.org/proftpd)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully