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 05(2021/10/21) [TOC] ## 指令 - terminal : `指令 參數 目標`(KISS 原則) - 變更擁有者 - `sudo chown <想要換成的owner> <檔名>` 變更owner - `sudo chown -R <想要換成的owner> <檔案目錄>`變更一個檔案目錄下的所有檔案的owner - `suid` setuid - ex: `-rwsr-xr-x` 在 user 執行權限的部份不是 x 而是 s - 執行者將具有該檔案擁有者的權限 :::info **用途** `passwd` 要讓任何人都可以執行來改密碼,需要改到 `/etc/shadow`,而這檔案需要 root 權限才改的了。setuid 讓任何人執行時都可以變成 root,來改密碼。 駭客可能的利用方法:在你的系統裡偷放一個有 setuid 的程式,這樣他隨時能利用。 防治方法:用 `find <blahblah>` 來找系統裡哪些程式有打開 setuid。 ::: - `sgid` setgid - ex: `-rwxr-sr-x` 在 group 執行權限的部份不是 x 而是 s - 執行者將具有該檔案擁有群組的權限 - suid 跟 sgid 可能會出現在權限上不是寫小寫 s 而是大寫 S 的情況 - 代表該欄位並沒有執行權限 - ex: chmod 7666 file - 雖然設有 suid 跟 sgid 但 666 表示他的擁有者跟群組都沒有執行權限 - `sticky bit`:最後一個欄位是t - 例如: `rwxrwxrwt:`除了擁有者和root外,其他人不能刪他或是移動他 - 設有 sticky bit 的目錄底下任何人都可以新增修改檔案,但只有本人跟 root 可以刪除 - ex: `/tmp` > - Sticky bit 一般用於/tmp目錄,以**防止普通用戶刪除或移動其他用戶的檔案** - 修改權限 - 文字修改: - ex: chmod u+s g+s o+t <檔案名稱> - 數字修改: - user/SUID(`s`): 4; group/SGID(`s`): 2; other/SBIT(`t`):1 - `chmod 4777 <file>` user擁有可讀可寫可執行的權限,且其他人不能改(rwsrwxrwx) 小寫s變成擁有者的權限 - `chmod 4664 <file>`:如果是大寫`S`,需要給它`x`的權限才會變小寫`s` - ![](https://i.imgur.com/jSwxWhm.png) - 雖然other的權限只有執行,但是user`-rwsr`裡面有s,導致其他人執行後擁有和user一樣的權限 - ACL(Access Control List) > ACL 可以針對單一使用者,單一檔案或目錄來進行 r,w,x 的權限規範 - `getfacl <檔名>`查看檔案權限 - `setfacl -m u:<使用者名稱>:<給啥權限> <檔名>` 幫某人增加權限 - `setfacl -x u:<使用者名稱> <檔名>` 移除某人的權限 - [鳥哥的 ACL](http://linux.vbird.org/linux_basic/0410accountmanager.php#acl_talk) - 針對特定用戶更改權限 - 檔案權限第一個 bit 意思 (用 `ls -l` 看到的) - `-` -> file - `d` -> directory - `l` -> link - `b` -> block device,例如硬碟 - `ln` link - 像是 windows 的捷徑(簡化路徑) - symbolic link (soft link) - 可以跨Filesystem - 創建一個softlink指令:`ln -s filepath linkname` - soft link 存的就是一個字串,所以大小就是字串大小 - 也因此所以 soft link 的檔案路徑可以隨便亂打,在建立時不會出錯 - 你對 soft link 做任何事都只會對 file 影響,link 本身不變 - 存的是一個**連結**,不是檔案 - 刪掉被 link 的 file 本體,link 還會在,只是要去用他才會出錯 - ![](https://i.imgur.com/R3M5BA6.png) - hard link - 不可以跨Filesystem - 創建一個hardlink指令:`ln <filepath> <linkname>` - 看起來和一般的檔案一樣 - 如果我寫東西在link,hard link和link的內容會是一樣的 - 備份用(兩個是一樣的檔案) - 刪掉一個另一個還會活著 - inode 編號會一樣 - `ls -i` 看得到 - 代表是同個檔案 ### inode 如果是同個inode就是同個檔案,不同就是不同的檔案 ![](https://i.imgur.com/Gq1Y9Re.png) :::info **KISS rule (Keep it simple, stupid)** - Do one thing and do it well. - Unix 裡面有很多小東西,每個小東西都只做好他的那一件小事情,而且可以串接起來。 - 很多參數會有慣例,讓系統管理者能夠很直覺做事: - `-v` verbose,把詳細過程印出來 - `-a` all or archive - `-r` recursive ::: ### sudo - super user do - sudo 執行完之後就恢復為普通使用者 - 好處:可以確認有哪些權限、會記錄下來 - 看哪個使用者可以用哪些指令,寫在 `/etc/sudoers` 裡 - root ALL(可以從任何地方登入)=(ALL:ALL)(任何身分) ALL(任何指令) - `visudo` 會幫你把你的變更先暫存起來,出錯會警告你 - `sudo su` 切換成root - 變成超級使用者可以做任何事情(不需要打密碼) - `sudo su - <使用者>` 切換成別的使用者 - 有`-`才會切換環境變數,此時要輸入的密碼才是"要切換使用者的密碼" :::warning **沒事不要用 `su`** - 通常只有切到另一個使用者時會用 `su <別人username>`,被問到密碼是要輸入對方的密碼 - 盡量別分享密碼 - `sudo su user` 跟 `sudo su - user` 的差別在於前者**環境變數**維持上個使用者,後者則會更新環境變數 ::: ### apt - `sudo apt install <要安裝的套件>` 下載要安裝的套件 - `sudo apt update` 檢查軟體有沒有更新,也把軟體列表都抓下來了 - 軟體列表會 cache 在 `/var/lib/apt/lists/` 裡 - `sudo apt upgrade` 升級軟體套件 - `sudo apt remove <要刪的東西>` 移除某程式,但不完全刪掉所有檔案(會留下一些設定檔,裡面的import 的東西也還存在) - `sudo apt purge` 徹底移除無用的套件 - `sudo apt autoremove` 自動幫你把不需要的東西刪掉 - `sudo apt clean`在安裝完套件後,並不會把安裝包移除掉,會一直占用空間,因此可以定期使用這個指令去刪除已安裝套件的安裝包 - `sudo apt autoclean` 自動幫你把過期的安裝包刪掉 (現在電腦上沒有安裝的軟體的安裝檔刪除) - `sudo apt install aptitude` - `sudo apt search <套件>` 搜尋套件 - `sudo apt remove <套件> -P` 完整的刪除,但是快取檔案還是存在 - `sudo apt show <套件名稱>` 顯示相關套件 - `sudo apt remove <套件> --purge` ### aptitude - `sudo aptitude hold sl` 軟體不會繼續更新,就hold在那邊 > 有 99.999% 不會記得unhold [name=BT] - `sudo aptitude unhold <套件名稱>` 取消hold,軟體會繼續更新 :::info 有些舊文章會教你用 `apt-get` ,那是在 `apt` 出現之前常用的東西。 ::: :::info **repository,簡稱repo** - 有開源貢獻者,幫你把程式打包好放在同一個軟體庫裡,你就不用 Google 「Firefox 破解版」找怪怪的網站載程式 - 會有世界各地志願者 mirror 起來,讓伺服器跟使用者離的越近越好 - 有一個就在暨大,BlueT 本人經營:**[OSS Planet](https://mirror.ossplanet.net)** ::: - `dpkg -L <package name>` 找你電腦有沒安裝這軟體,和檔案都存在哪些地方 - `apt-cache policy <package name>` 顯示套件來源及個別套件的優先性 - `whereis <package name>`: 找到套件執行檔路徑 - `dpkg -S <path of a file>`: 找說這個檔案是在安裝哪個程式的時候放過來的 - `sudo apt show <package name>` 顯示套件相關資料 - 安裝這個套件時,其他需要的套件 (dependancy) ![](https://i.imgur.com/hvdjpC0.png) - `dpkg -al` 列出你安裝的所有東西 - `sudo aptitude save-upgrade` 安全的升級不會亂刪東西 - `sudo aptitude hold <package>` 保留這個版本,以後不會幫你更新(取消用 `unhold`) - 有點危險,因為就等於是放著讓它不更新漏洞 - `sudo aptitude search` - 重點在 : 他會有點像是圖形介面(看了很舒服),移動光棒 > 身心舒暢[name=blueT] - 按`\` - `/^<關鍵字>` 從開頭開始比對搜尋 - `$` 結尾 - TUI(terminal user interface)操作方式 - gg 確認操作 - Ctrl-T 找到所有指令的快速鍵 :::info **gcc** - 安裝 ```shell= sudo apt install gcc ``` - 編譯 .c 檔 - `-o` 後面接編譯完的檔案 叫甚麼名字 ```shell= gcc <file name> -o <file name> ``` - 執行 - 是要執行編譯過後的檔案喔 ```shell= ./<file name> ``` ::: :::danger 等等要用的咚咚,不要刪喔 ```c= #include <stdio.h> #include <unistd.h> int main() { printf("The uid is: %d\n", geteuid()); return 0; } ``` :::

    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