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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: 1091, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book Week 04(2020/10/15) === :::info ## 預習方向 - password - `/etc/passwd` - `/etc/shadow` - `/use/bin/passwd` - 權限, setuid, setgid - `passwd -S` 密碼狀態 - 多工執行 / 依序執行 - 套件管理 - `apt` - `aptitude` - 文字編輯 - vi, vim, nano - `ssh`, `telnet` - `ifconfig` - OSI 七層架構 / TCP/IP 四層架構 - nginx ::: ## 上週作業 - 網頁: /var/www - 信件 : - /var/mail - /var/spool - /var/log : - 記錄檔(純文字檔) - 每隔一段時間作壓縮,防止過度膨脹 - /etc/ 不重要 > 當你覺得設定檔很重要,裡面涵蓋了許多你的特殊設定,不想在其他磁區壞掉時影響到此磁區,便可以做切割(保護作用),但不宜切割太大(ex:2T) - swap : 1,20G左右。不用多大 ( 200、300G ) 、也不能太小 ( 3、4G ) ## 基本指令(續10/08) ### 設定密碼 - `passwd`: 更改登入中使用者的密碼 - `/etc/passwd`:儲存關於帳號相關資訊 - name - passward = x - uid(user id): 對應使用者有什麼權限 - uid 是 1000 開始, - gid(group id): 對應使用者有什麼權限 - `/etc/shadow` - 因是加密後的文件,要加 `sudo`,不然會是亂碼 - `id + "使用者名稱"`: 列出使用者的 uid 以及他屬於哪些群組 ![](https://i.imgur.com/fwqTvsq.png) - `apt`: ubuntu 下管理套件的工具 - 有 `apt` 、 `apt-get` 、 `/apt/cache` - 一般安裝時使用 `apt-get` , `apt` 使用其他套件管理功能 - `sudo apt update`: 更新軟體源source list - `sudo apt upgrade`:更新套件 - `sudo apt list --upgradable`: 查看可更新的套件資訊 - `sudo apt install "要安裝套件名"`: 安裝套件 - 安裝套件前建議先更新軟體源 - `sudo apt remove "要移除的套件名"`: 移除不要的套件 - `aptitude`: 提供圖形化介面 - 不只在安裝時會自動先執行 `apt-get update` 來更新套件資料庫之外,還會把相依的套件一起給裝起來,解決相依性的問題 <!-- - 會自動更新軟體源(`apt update`) 跟前一行相同 --> - `aptitude` 指令可以做各種事,不用像 `apt-get` 要分成 `apt-get`、`apt-cache` 等不同用途的指令 - 安裝: `sudo aptitude install ` - 開啟: `aptitude` - 退出: `q` ## 文字編輯器 ### vim - 安裝: `sudo apt install vim` - `vim "文件名稱"`: 編寫文件,如果沒有打檔名可以稍後再儲存 - 使用指令: 按`esc`接著打下表指令 |指令|用處| |---|---| |:w|存檔| |:w!|在唯獨模式下強制存檔,不過,到底能不能寫入, 還是跟你對該檔案的檔案權限有關。| |:q|離開| |:q!|通常有編輯之後如果直接離開,會失敗,這時候就要用強制離開| |:wq|存檔後離開| |:e!|還原到剛開啟檔案的時候| |ZZ|檔案沒有更動,則不儲存離開,若檔案已經經過更動,則儲存後離開| - `vimtutor`:可以練習所有指令(指令教學 通常花1hr) #### 一般模式 - `hjkl` : 上下左右 > 如果你要假裝自己很厲害,這個一定要背起來 [name=郭子緯] - `i`: insert 當前開始編輯 - 編輯是以小白框前面那格開始 - `I`:在開頭打字 - `a`: 下一格開始打 - `A`:在結尾打字 - `u` : 復原 - `x` : 刪除 - `數字 + 大寫G` : 移到數字那行 - `:行數`: 也可以使用 - `$`: 該行最後面 - `yy`:複製 - `p` : 貼上 - `/你要找的東西` : 搜尋 - `n`: 往下找 - `N`: 往上找 - 正規表示法 - `^`: 起頭為你要找的字母..的那行 - `$`: 規定結尾 [[Linux] vi 與 vim 指令一覽表整理](https://code.yidas.com/linux-vi-vim-command/) #### vim 設定 <!-- - `~/.vimrc`: vim 設定檔 - `set cursorline`: 標示編輯中的那行 - `set nu` : 顯示行數 - `set tabstop=4`: tab 設定為空 4 格 - `set shiftwidth`: 縮排格數 - `expand`: --> ##### 我有用的參數 |說明|指令| |---|---| |set cursorline|光標所在的那一行會有底線,幫助尋找光標位置| set nocompatible|讓 VIM 工作在「非相容模式」下| set nu|顯示行號 set encoding=utf-8|編輯器使用 UTF8| set t_Co=256|256 色的 Vim syntax on|語法上色顯示 set shiftwidth=4|設定縮排寬度 = 4 set tabstop=4|tab 的字元數 set expandtab|用 space 代替 tab [練習網站](https://regex101.com/) [視覺化練習網站](https://ihateregex.io/playground) ### nano - 指令都會在下方,不像 vim 一樣要背指令 - `^` : 這東西是ctrl - `ctrl + x`:離開 ## 網路 ### 網路等級 - `sudo apt install net-tools`: - `ifconfig`: 查看電腦 ip - 或 `ip address`, 可以縮寫 `ip a` - `inet`: ipv4 - `netmask`: 可以拿來算是否在同個網段 - `broadcast`: 廣播位置 - 尋找網路下有哪個 ip 可以提供什麼服務 - `inet6`: ipv6 - IP 有分 A, B, C, D, E 五等級 ![](https://i.imgur.com/jS0eXRc.png) - 計算net ID: ip 跟 mask 做 & 運算 :pencil2: 計算題 ip : 192.168.1.11,子網路遮罩 : 255.255.255.0 轉成二進位 11000000.10101000.00000001.00001011 11111111.11111111.11111111.00000000 ---AND------------------------------------------ 11000000.10101000.00000001.00000000 網域: 192.168.1.0 (0 跟 255 有特殊用途不能用) - 實際分配是 1-254 -> IP 位於 192.168.1.1 ~ 192.168.1.254 都在同一個網域下 - 子網路遮罩: 可以用 `/` 接在ip後面表示該 ip 所在網域 > example <!-- 我不會換行QQ --> > 上圖 `192.168.1.11` ip 可將其網域寫成`192.168.1.11/24` - 補充特殊用途 ``` xxx.xxx.xxx.0 整個網段(並非router) xxx.xxx.xxx.1 通常用做DNS xxx.xxx.xxx.254 當gateway xxx.xxx.xxx.255 當broadcast ``` :::info ### 0.0.0.0 In the Internet Protocol Version 4, the address 0.0.0.0 is a **==non-routable meta-address==** used to designate an invalid, unknown or non-applicable target. To give a special meaning to an otherwise invalid piece of data is an application of in-band signaling. In the context of servers, 0.0.0.0 means "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs. In the context of routing, 0.0.0.0 usually means the default route, i.e. the route which leads to "the rest of" the internet instead of somewhere on the local network. ### 255.255.255.255 **==A broadcast address==** is a logical address at which all devices connected to a multiple-access communications network are enabled to receive datagrams. A message sent to a broadcast address is typically received by all network-attached hosts, rather than by a specific host. A special definition exists for the IP broadcast address 255.255.255.255. It is the broadcast address of the zero network or 0.0.0.0, which in Internet Protocol standards stands for this network, i.e. the local network. Transmission to this address is limited by definition, in that it is never forwarded by the routers connecting the local network to other networks. ::: ### TCP/IP四層模型 ![](https://i.imgur.com/bQwBXMe.png) - http、https 都算 Application layer - Transport: TCP UDP - Internet: IP - Link: 網路卡屬於這層 ## 遠端連線伺服器 - 登入類型 - telnet、rsh - 明文傳輸、未加密 - 連線目的地伺服器,然後輸入帳號和密碼以驗證身分 - 容易被偽裝,竄改資料 - ssh(secure shell安全的殼) - 可用 `ifconfig` 查 ip(inet) - windows 是用 `ipconfig` - Xdmcp、VCP、RDP - 圖形介面 ### SSH - 全名 : Secure Shell 安全外殼協定 - 解決telnet不安全的問題 - 通常是22port - 技術簡介 <br>使用非對稱金鑰系統,透過兩把公、私鑰進行加解密 <br>用對方的公鑰加密,對方收到檔案後用自己的私鑰解密 ![](https://i.imgur.com/JzZSgl2.png) - ssh連線 <br>![](https://i.imgur.com/v2bSyy5.png) - 遠端連本機: `ssh <userName>@localhost` 或是 `ssh 127.0.0.1` - `sudo apt install ssh` 安裝ssh server版 - 預設: client版 > 用 `ssh` 最好有個好習慣在後面順手加 ` -v` ,可以看到 debug 訊息。\ > 如果用指令不知道他在運行什麼,可以加` -v`,就可以看到它的運行過程了。[name=BlueT] - 離開: `exit` - [免密登入](https://xenby.com/b/220-%E6%95%99%E5%AD%B8-%E7%94%A2%E7%94%9Fssh-key%E4%B8%A6%E4%B8%94%E9%80%8F%E9%81%8Ekey%E9%80%B2%E8%A1%8C%E5%85%8D%E5%AF%86%E7%A2%BC%E7%99%BB%E5%85%A5) - `ssh-keygen -t rsa` 生成金鑰 - `ssh -v [username]@localhost` 使用ssh連本機 - `ssh -v localhost` 使用ssh連本機,並自動填入username - `ssh-copy-id -i id_rsa.pub [username]@localhost` 複製金鑰到遠端本機 - 公鑰位置 - `~/.ssh/authorized_keys` 別人連進來 - ![](https://i.imgur.com/LJN9bMp.png) - 開源SSH - openSSH、OSSH - SSH 的安全驗證兩種級別 - 第一種級別(基於密碼的安全驗證) - man in middle attack > ssh 可以也不可以避免中間人攻擊 - 第二種級別(基於金鑰的安全驗證) <!-- - scp、ftp、sftp --> ### DNS 網域名稱系統 - IP 是一串數字,不好記憶,因此需要有 Domain name - DNS 可以將 Domain name 對應到 IP - DNS tree ![](https://i.imgur.com/BfAi3sr.png =400x) - 世界上有 13 台 root DNS IP ,如果有必要重新查找IP,會由這 13 個root去開始查找 - `dig +trace <domain name>`: 列出DNS的查找IP流程 - `dig +trace @8.8.8.8 www.google.com` - `hostnamectl`: host name control - `hostnamectl set-hostname <要修改的hostname>`: 更改 hostname ## Q & A Q: 為什麼 upgradable 前面是兩個 dash ? - 參數規定 ~ 可用 `man` 來看如何下參數 - 像是部份指令 `--help` 可以得知如何下指令一樣 ~~沒有道理XD~~ <!-- 10.2.54.3/25 192.168.1.0/25 -->

    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