張可葭Ivy Chang
    • 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
    ###### tags: `1121` `lsa` `ncnu` # 基礎指令 & SSH - Book mode: https://hackmd.io/@ncnu-opensource/book [TOC] ## 基礎指令 ### SGID - Set GID - 指令設定 - `chmod 2???? <filename>` - `chmod g+s <filename>` - 只能用在二進位檔案 - 讓在群組所屬的目錄底下產生的資料屬於群組,而非使用者有效群組 - 舉例 ### 與安裝,下載,更新相關 - `apt` - `sudo apt install <packagename>`:安裝軟體 - `sudo apt update`:更新系統已經安裝軟體的package與版本資訊 - `sudp apt upgrade`:升級系統安裝的軟體 - `sudo apt dist-upgrade`:upgrade+升級系統已安裝軟體的相依性 - `wget` - `sudo wget <網址>`:從指定的網址下載內容 - `dpkg` - `sudo dpkg -i <filename.deb>`:安裝指定deb檔 ### SBIT - Sticky Bit - 指令設定 - `chmod 1??? <filename>` - `chmod o+t <filename>` - 雖然權限是 777,但是限制只有擁有者跟root才能刪除資料 - 限制非擁有者刪除檔案 - 舉例 ### 與打包,壓縮相關 - 根據檔案的副檔名選擇相關的指令 - `*.gz`(最被大眾接受) - `gzip<filename>`:壓縮檔後檔名為 filename.gz - `gzip -d<filename>`:解壓縮 - 適合電腦較差的環境下使用 - `*.bz2` - `bzip2 <filename>`:壓縮檔後檔名為 filename.bz2 - `bzip2 -d<filename>`:解壓縮 - `-k`:保留原始檔案 - `*.xz` (盡可能壓縮,電腦性能要好) - `xz<filename>`:壓縮檔後檔名為 filename.xz - `xz -d<filename>`:解壓縮 - `-k`:保留原始檔案 - `*.tar`(打包,不是壓縮) - `tar[-z|-j|-J] [c|x] [v] [-f <filename>]<filename>` - `-z`:透過gzip的支援壓縮,檔名建議為*.tar.gz - `-j`:透過bzip2的bzip2的支援壓縮,檔名建議為*.tar.bz2 - `-J`:透過xz的bzip2的支援壓縮,檔名建議為*.tar.xz - `-c`:建立打包檔案 - `-x`:解打包,壓縮 - `-v`:列出正在處理的檔案名稱 - `-f`:指定打包,壓縮後的檔案名稱 - `tar -zcvf <destination> <source>` - `tar -zxvf <destination> <source>` - `*.zstd` - `sudo apt-get install zstd` - `zstd <filename>`:壓縮,壓縮檔後檔名為 filename.zst - `zstd -d <filename>`:解壓縮 ### 與process有關 - process:系列執行中的程式 - `ps`列出process的資訊 - `ps -aux` - `-A`:所有的process都列出,與`-e`具有同樣的效用 - `-a`:不與 terminal有關的所有process - `-u`:有效使用者(effective user)相關的process - `-x`:通常與`-a`這個參數一起使用,可列出比較完整的資訊 - 欄位意思 - USER:process 擁有者 - PID : process id - %CPU : 佔用CPU的使用率 - `%MEM`:佔用的實體記憶體的比例 - VSZ:佔用的虛擬記憶體大小 - RSS:佔用的記憶體大小 - `pstree`:用樹狀圖的方式列出process的關係 - `-a`:顯示全部 - `-p`:顯示PID - `-np`:用PID排序列出 - `top`:動態觀察 process - 依據CPU使用率排序process - 欄位意思 - PID:每個process的識別碼(PID) - USER:該process所屬的使用者 - PR: Priority的簡寫,程序的優先執行順序,越小越早被執行 - NI: Nice 的簡寫,與Priority有關,也是越小越早被執行 - VIRT:虛擬記憶體使用量 - RES:硬碟記憶體使用量 - SHR: 共享記憶體使用量 - S: process 狀態 - %CPU: CPU 的使用率 - %MEM: 記憶體的使用率 - TIME+: CPU使用時間累加 - COMMAND:指令 - `whowatch`:追蹤使用者的狀況 ### 與磁碟,記憶體相關 - `df`:列出檔案系統的整體磁碟用量 - `-a`:列出所有檔案系統 - `-h`:容易閱讀的格式 - 欄位內容 - Filesystem: 代表該檔案是在哪個 - partition: 所有列出裝置名稱 - 1k-blocks: 數字單位是1KB - Used: 使用掉的磁碟空間 - Avail: 剩下的磁碟空間 - Use%: 磁碟的使用率 - Mounted on: 就是掛載的目錄(掛載點) - `lsblk`:list block device,列出所有儲存裝置 - `f`: 列出磁碟內的檔案系統名稱 - `-p`: 列出完整檔案名稱 - `-t`: 列出磁碟詳細資料 - 欄位內容 - Name:裝置的檔名,會省略/dev等前面的目錄 - RM: 是否可以為卸載裝置(removable device) - SIZE:容量 - RO:是否為唯獨裝置 - TYPE:磁碟(disk),分隔槽(partition)或唯獨記憶體(rom)等輸出 - MOUTPOINT:裝置的掛載點 - `free`:觀察記憶體與Swap使用情況,預設以kb顯示 - `-b`:以bytes顯示 - `-m`:以mb顯示 - `-g`:以gb顯示 - 欄位內容 - `total`:總量 - `used`:已使用量 - `free`:剩餘可用 ### 與網路相關 - `dig`:查 DNS server - `-x`:反向查詢 - `dig <domain_name>` - `dig -x <ip>` - `nslookup <domain_name>`:看DNS server想關資料,似dig - `host <domain_name>`:domain轉IP - `whois <domain_name/ip>`: - domain - 由誰註冊 - 什麼時候到期 - ... - ip - 屬於哪個國家 - 區段多大 - 哪個機構在管理 - ... - `ifconfig`:查看目前已啟動網卡的相關資訊 - 安裝:`sudo apt install net-tools` - `-a`:查看所有網卡 - `ifconfig<網卡名稱>`:顯示指定網卡的資訊 - `sudo ifconfig<網卡名稱>down`:關閉網卡 - `sudo ifconfig<網卡名稱> up`:開啟網卡 - `route`:看直接的routing table - 安裝:`sudo apt install net-tools` - `-n`:會把能變成數字的資訊變成數字,主機名稱以IP顯示 - `iproute2`:網路參數綜合指令,可以取代ifconfig,route - `ip[option][動作][指令]` - option: 可設定的參數,以`-s`為主 - `-s`:顯示出該裝置的統計數據(statistics),例如總接受封包數等 - 動作: 可以針對哪些網路參數進行動作 - `link`: 關於裝置 (device) 的相關設定, 包括 MTU, MAC 位址等等 - `addr/address`: 關於額外的 IP 協定, 例如多 IP 的達成等等 - `route`: 與路由有關的相關設定 - 指令 - `show`: 查閱 - `set`: 設定 - `ip [-s] link [指令]` - `show` : 查閱 - `ip [-s] link show`: 查閱所有網卡資訊 - `ip [-s] link show <網卡卡號>`: 查閱指定網卡資訊 - `set` : 設定 - `ip [-s] link set <網卡卡號> up`: 開啟網卡 - `ip [-s] link set <網卡卡號> down`: 關閉網卡 - 其他: address 設定網卡位址, name 設定網卡名稱, mtu 設定網卡最大的傳輸單元 - `ip [-s] addr [指令]` - `show` : 查閱 - `ip addr/address show` : 查閱 IP 參數 - `add / del` : IP 參數增加或刪除 - `ip address [add|del] [IP參數] [dev 裝置名] [相關參數]` - `ip [-s] route [指令]` - `show` : 查閱 - `ip route show/list` : 查閱 routing table - `add / del` : 增加或刪除 route - `ip route [add|del] [IP或網域] [via gateway] [dev 裝置]` - `iftop`: 網路的即時流量 - `sudo apt install iftop` - `sudo iftop -Pp <網卡名稱>` - `-p`: 顯示 port 相關資訊 - `-P`: - `netstat`: 目前電腦網路的詳細狀況 - `netstat -ntupl` - `netstat -an` - `-a`: - `-r`: 列出 routing table , 功能同 `route` 指令 - `-n`: 不要把數字變不是數字, e.g. 主機名稱以 IP 顯示 ` - `-t`: 顯示 tcp - `-u`: 顯示 udp - `-p`: 列出 PID 與 Program 的檔名 - `-l`: 目前監聽到的 - `ss`: Socket Statistics, 列出 Sockets 的統計資訊 - sockets: - 跟 netstat 指令類似, 從 kernel 讀取數據, 所以速度較快 - `-l` : 列出全部開啟的埠號 - `-pl` : 列出開啟 Socket 的 process 名稱 - `-a` : 列出所有資訊 - `-t` : 只列出 TCP Sockets - `-u` : 只列出 UDP Sockets - `-x` : 只列出 Unix Sockets - `-4` : 只列出 IPv4 Sockets - `-6` : 只列出 IPv6 Sockets - `ss -t4lp`: 系統上所有用 IPv4 開啟的 sockets 與對應的 process ### .bashrc - 給bash的設定檔 - 如果想每次啟動bash都會生效,可以寫進檔案 ```bash= alias nn="netstat -ntpul" ``` - `source .bashrc`:設定指定的環境 :::info 現代的 UNIX-like 作業系統 (特別是使用了 systemd 的 Linux 發行版) 中,網路介面卡 (Network Interface Cards, NICs) 的命名採用了 **預測性網路介面設備名稱** (Predictable Network Interface Names) 的機制 以下是一些常見的組件和它們的意義: - en: 代表 **Ethernet** - p0: 代表 **PCI Bus 0** - s1: 代表 **Slot 1** enp0s1 這個名稱基本上告訴我們這是一個 Ethernet 網路卡,位於 PCI Bus 0 和 Slot 1 上 ::: ## 遠端連線 Telnet(少用/不安全) * 支援的使用者軟體比較多 * 傳輸資料時未加密(明文傳輸) * 有心人士擷取封包 => 裸奔的資料(帳號密碼) * 沒有驗證機制,無法保證是否為本人發送 * 連線流程: * 終端使用者(本機)與遠端伺服器建立連線,port號為 23號 * 终端使用者進行遠端伺服器帳號密碼登入 * 遠端伺服器回應终端使用者 - SSH ```bash= ssh [user@]hostname ``` - 加密方式 - 對稱式 - 接收端與發送端皆持有相同的密鑰,用來做加密 - 非對稱式 - 一位使用者分別擁有公鑰(可給指定對象)和私鑰(自己保留用) - 利用其中一支加密則一定要用另一支解密 - 過程 - 加密 原始data -> 寄件者私鑰加密&收件者公鑰加密 -> 加密data - 解密 加密data -> 收件者私鑰解密&寄檢者公鑰解密 -> 原始data sudo service ssh start/stop/restart `sudo service ssh status` 確認伺服器狀態

    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