NCNU-OpenSource
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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 New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 1101, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book # Week 07(2021/11/04) [TOC] ## SSH - `ssh -X` 遠端打開圖形化介面視窗 - `ssh -o ConnectTimeout=3 <IP>`:等待連線時間超過3秒就斷線 - `ssh -i <私鑰路徑> <user>@<ip or domain>` 當要用憑證來登入主機時附上金鑰 - 私鑰路徑通常放在 `~/.ssh/id_rsa` - 私鑰權限應該要設成 600 #### 什麼是憑證? 具有一定證明事實等的效用的物件 憑證常被用來證明持有者的能力 #### 如何利用憑證進入遠端伺服器 透過公鑰 :::info 非對稱式金鑰系統 - 透過公鑰與私鑰(public key and private key) 來進行身分驗證 - 公鑰與私鑰必須成對 - 公鑰(public key): 提供給遠端主機進行加密(認證) - 私鑰(private key): 在本地端用來進行資料加密(簽章) - 私鑰是不能夠外流的! ::: > 前言: 想要透過憑證來進行遠端連線 #### 如何生成憑證 在==本機==產生一對鑰匙 - `-t` 用哪一種加密方式產生鑰匙 ```shell= #本機 ssh-keygen -t rsa ``` ![](https://i.imgur.com/u3mY2A0.png =400x) ```shell= #本機 cd ~/.ssh/ ``` 查看 `~/.ssh/`下的 檔案 - `id_rsa`:私鑰 - `id_rsa.pub`: 公鑰 --- > 方法一: 在==遠端主機==裡面新增一個檔案 ```shell= #遠端 touch authorized_keys ``` 遠端主機用ssh連線 複製==本機== `id_rsa.pub` 放入==遠端主機== `~/.ssh/authorized_keys` ```shell= #遠端 sudo vim authorized_keys ``` 查看是否有放入authorized_keys ```shell= #遠端 cat authorized_keys ``` > 方法二: 直接把金鑰透過指令複製過去 ```shell= #本機 ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<ip> ``` :::info 公鑰傳給對方後,對方擁有我的公鑰,我就可以用我的私鑰進到他的伺服器 - 連到對方的伺服器 1. 將公私鑰傳到對方的伺服器 2. 用帳號密碼 ::: ### ssh 設定檔 - 放在`/etc/ssh` - ssh_config:針對client端的設定檔 - sshd_config:針對server端的設定檔 #### 查看 ssh_config ```shell= sudo vim ssh_config ``` - 藍字註解起來代表已預設 >![](https://i.imgur.com/2XSKnxE.png =400x) - 下面縮排選項的設定都是用於該Host >![](https://i.imgur.com/wwrkN5y.png =250x) 1. ForwardAgent 驗證代理 - 讓本地的 SSH key 可以在遠端 server 轉送 ![](https://i.imgur.com/Pp7AZ0C.png =200x) 2. PasswordAuthentication 可不可以使用帳號密碼來做登入 3. CheckHostIP 發現已連過主機ip位址不同就會提醒 4. Port 22: 預設會連線到server的port 5. IdentifyFile 預設查找放私鑰的文件路徑 > ![](https://i.imgur.com/7t9gcF1.png =250x) 6. Cipher - 設定加密演算法 (位置愈前面代表愈先使用) #### 查看 sshd_config - 若這台電腦扮演 server 端,相關設定都存在這裡 - 預設連進來的是port22 - ListenAddress 所有介面卡都會去監聽ssh 的要求 - HostKey: server端的私鑰 - PermitRootLogin **prohibit**-password: 禁止root 權限登入 - PubkeyAuthentication: 能不能允許使用者產生公鑰私鑰 - PasswordAuthentication: 可不可以用~~憑證~~帳號密碼進行登入 :::info log 檔(日誌)等級(依重要性遞減) 所有欲紀錄的訊息等級倘若大於等於INFO(例如: FINAL、ERROR),便會被記錄下來,反之,若紀錄的訊息等級小於Debug時,便不會被記錄下來。 - FATAL - 錯誤事件嚴重會導致應用程式退出 - ERROR - 錯誤事件,但不影響系統繼續執行 - WARN - 警告潛在的錯誤訊息 - INFO - 平常運行過程中的相關資訊 - DEBUG - 更詳細的資訊,對於需要Debug時,很有幫助 ::: - ForwardAgent 驗證代理 - 讓本地端的SSH key在遠端server 上進行轉述 - 讓伺服器驗證這個身分是不是你 - 在不同的電腦都會有自己的私鑰,私鑰絕對不會傳出去 - 一台電腦可以有不止一組公私鑰對 - 把使用者端的公鑰放到伺服器A(跳板機),...沒聽到O.O - 如果要連伺服器B,都要透過伺服器A連線 - https://www.ssh.com/academy/ssh/agent ![](https://i.imgur.com/ktKH4f1.png) ![](https://i.imgur.com/AKcWKE2.png =400x) - BT 補充 - 如果修改過 ssh_config 的話,會在應該要更新時不更新(?) - 所以現在都不讓你改 ssh_config了 - 直接多用一個 ssh_config.d/*.conf 讓你在裡面改 - X11 forwarding - client 端預設是關的,用 `ssh -X` 來打開 - `-v` 可以看現在連線的流程 - `-X` 打開圖形化介面(大寫) - `-x` 關閉圖形化介面(小寫) - 會把使用者在圖形化界面的操作都往伺服器送 > 在 linux 你下選項時可以 -v -X,也可以連起來寫成 -vX,你就可以一直連下去連到連它媽都不認識 [name=BT] - strictHostKeyChecking - `-o "一些東西(參數)"` - 讓你可以在這次連線暫時改一些參數 - ex. `ssh -vX -o "StrictHostKeyChecking=no" <使用者>@<位置>` - ssh 流程 1. client 先去看`/etc/ssh_config` - 找自己有沒有ssh key可用,對方有沒有public key。(如果沒有才會打帳號密碼) 2. client 的 known_hosts - 會去嚴謹的檢查一些特徵(server 的 fingerprint),下次連線之前確認這些東西,如果有變化,會跳出 Error 提醒你 3. server 看 sshd_config - 告訴 client 能夠用哪些方式來登入 server - key - password - 私鑰公鑰怎麼用的 1. 我是 client,擁有私鑰和公鑰 2. 用密碼登入了 server ,把我的**公鑰**放進我想登入的那台 server 的那個使用者的 authorized_keys 檔案裡 >【authorized_keys】: 專門放大家的公鑰,連線的時候就會去查找這個檔案裏面的公鑰(裡面每一行都是一個公鑰) 3. 之後我就能用自己的**私鑰**,跟 server 登入。(私鑰不能給別人,要自己保管好) 4. server 發現自己 authorized_keys 裡有這組 key pair,就放行讓他進來 - 在google 查 `what is my ip address`,看自己的ip位置 <!-- 偷偷業配個 https://wtfismyip.com/ ,還能用 `curl https://wtfismyip.com/json` 在terminal 抓到純文字的結果 --> - ssh -vX : 我在遠端開啟,但是畫面呈現在本機,如果我在本機使用圖形化界面,會很慢,因為他還要傳指令到遠端 - 兩個ip 會不一樣 - `midori`: 另一個瀏覽器 - 安裝midori瀏覽器 ```terminal= sudo apt install midori ```

    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