吳佳儀
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Linux(上) # chapter 01 ## 03/21上課筆記 ```bash Ctrl+a 移到命令行首 Ctrl+e 移到命令行尾 Alt+d 從光標處刪除至字尾 - touch ->touch 可以用來產生一個空白的檔案 Ex: touch aaa.txt / aaa.abc - p.s. Linux中檔案的大小寫是有區分的 Windows下則沒有 - tab的其他用法: 當檔名過長時按tab鍵,系統會自動填寫後續的內容 Ex: gedit a + (tab鍵) -> gedit aaa.txt - chmod + x (change model) ->賦予使用者執行權限 dmesg (dump message) | (管道pipe) more -->前面的輸出會成為下一個人的輸入 netstat -tunlp | grep 80 t(tcp)u(udp)n(不解析)l(listen)p(process) *如果沒有訊息,代表http沒有被啟動* ip 0.0.0.0 代表任意介面,無論是有限網路卡還是無線網路卡都可以提供ssh服務 - Linux 系統裡面第一隻被執行的程式 systemd(new) 啟動系統時會去檢查裡面有沒有enabled的屬性,來去作配置 init(old) ==>pid (process id) = 1 可以藉由pstree來看 - 資訊指令:(先切換超級使用者) uname uname -a (All) uname -r (版本資訊) cat /etc/redhat-release (查看centos的版本資訊) ``` ### 命令提示自符 ```bash 上鍵 取得上一個輸入過的指令 下鍵 往下 TAB 自動填寫後續的內容 Crtl+C 程式中斷 Crtl+Z 程式暫停,丟到背景 fg(fore ground前景) 程式繼續 jobs 取得被暫停的背景工作有哪些 man(manual) ls (list) 獲取所有ls指令的用法 pwd (print working directory) 顯示當前目錄 ls 顯示當前目錄,以及檔案 Linux下 .開頭的檔案為隱藏檔(白色是檔案,藍色是目錄) ls -a or --all 顯示當前目錄,以及檔案(包括隱藏檔) ls -a -l == (ls -al ; ls -la ; ls -l -a) option是可以加在一起使用的 ~ 代表使用者家目錄 whoami 查看目前使用者 ``` ### 更改hostname ```bash hostnamectl set-hostname centos7-2 bash (這個一定要記得打,不然改不過來) ``` ### 關機指令 ```bash shutdown -h now ``` ### 變更密碼 ```bash passwd + (使用者名稱) ->沒加預設更改自己的 ``` ### PS1 ```bash u:表使用者的帳號名稱。 h:主機名稱。 W:目前的工作目錄名稱 - PS1="\u@\h [$(date +%k:%M:%S)]> " 加入時間 !!僅限於當前的終端機有效,新開的終端機沒有 ``` ### 上課小程式1 ```bash touch aaa.txt(產生空白檔) echo "hi" 預設是顯示在電腦螢幕上 echo "echo hi" > aaa.txt (將hi導向aaa.txt) cat aaa.txt (觀察檔案裡面的內容,就會看到hi) *也可以使用 chmod +x aaa.txt ./aaa.txt (這樣就不會出現Permission denied的問題) ``` ### How To Reset Root Password On CentOS7 ```bash 1. 重新開機 2. 在開機介面的選單那裡,選擇第一個版本 3. 按 e 4. 找到裡面的ro,改成 rw init=/sysroot/bin/sh 5. Control+x 進入單人模式 6. chroot /sysroot 7. passwd root 變更密碼 8. touch /.autorelabel 更新資訊 9. 最後輸入 exit 10.reboot 重新開機 ``` ## # chapter 02 ## 03/28上課筆記 [程式練功網站](https://leetcode.com/) ``` " / " 屬於最高節點,"根目錄",所有檔案或目錄都是由 根目錄開始往下延伸,同時他也可以代表系統管理者的帳號 不同的分割區就可以變成不同的檔案系統 FAT、FAT32、EXFAT、NFFS屬於Windows下的檔案系統 ``` ``` Linux的世界:萬物皆檔案!! - dev(devise): 設備檔 Ex:滑鼠、虛擬機、終端機之類的 sda 的那個a代表scasi的第一顆硬碟 sdb 則代表第二顆,依此類推 - bin(binary): 執行檔所在目錄((一般使用者所使用 vim 文字編輯器 指令: vim a.txt - sbin(super user binary): 系統管理者所使用的執行檔 halt、ifconfig - home: 家目錄,每個使用者的家 <切換成超級使用者> cd /home useradd tom ls 就可以看到home底下的所有使用者的資料夾 - usr :第三方執行檔,函式庫,軟體套件之類的 類似於Windows下的Program file - var :可變動檔,像是log檔(紀錄檔),網路伺服器的家目錄也在裡面 - etc :系統的設定and管理,像是domain name、user帳號 etc下的resolv.conf是管理dns伺服器管理系統 是非常重要的資料夾,需要定期備分!! - boot: 開機核心存放位置,"vmluniz" - tmp :任何人皆有讀寫的權限 - *touch:新增空白檔案 - mnt(mount):掛載目錄 - proc(process) :正在執行的檔案 ``` ### 重點提醒 ```bash Linux系統下大小寫有別,Windows下則無區別 LANG=C 跟 lang=c 是不一樣的! cd /bin絕對路徑(看有無/) cd tom 相對路徑 cd ~ 回到自己的家目錄 cd - 切回原本的目錄 touch {a..d} 快速產生a~d四個檔案 touch {a..d}{1..4} -> a1~a4,b1~b4,c1~c4,d1~d4 ``` ### 目錄相關指令 ```bash pwd (print working directory) ls (list) 顯示資料夾的檔案跟目錄 ls -l(long) 顯示檔案的詳細資料 - 如果前面顯示b 則代表區塊 Ex:usb 如果前面顯示c 則代表字元設備 Ex:滑鼠、鍵盤 如果前面顯示d 則代表目錄 如果前面顯示l 則代表連結 如果前面顯示- 則代表檔案 - r(可讀) w(可寫) x(可執行) - ls -l test 只能看test資料夾下的檔案跟目錄,不能看到其屬性 ls -l -d test 這樣才可以看到完整資訊 ls -l -h 幫忙處理檔案大小的單位,方便查看 - cp(複製) mv(更改檔案或目錄的名稱) rm(移除) --- cp -r dir1 /tmp/將一個目錄全部複製至目的地 -r (recursive) ->將dir1目錄全部複製至tmp --- rm -i (inquery)詢問 rm -f (false) 不詢問 rm -r dir1 將目錄完全刪除 - mkdir(make directory)新建一個目錄 - less指令 與more相似,但功能更多 可以往前翻也可以往後翻 甚至是搜尋的功能 more 只能一路翻到底,不能往回翻 ``` ### 上課補充 ```bash cat的高級用法 用putty連到電腦 無法使用gedit( putty是文字化界面) cat <<EOF *開頭*> b.txt >Hello World >123 >456 >EOF *結尾* !不一定要EOF輸入其他文字也行,但切記要有開頭有結尾 - 合併檔案 cat b.txt c.txt cat b.txt c.txt > d.txt -- tail的高級用法 head -n 數字 檔案 > 列印出檔案的前3行 tail -n 數字 檔案 > 列印出檔案的後3行 - 如果只需要特定幾行的資訊 Ex: 3~5行 可以利用管道的方式 head -n 5 /etc/passwd | tail -n 3 - tail -f /tmp/b.txt 持續追蹤某個檔案的變化情形 ``` ### Quesion ```bash 命名法則皆為lib Q1 動態函式庫和靜態函式庫的差別?(.so) 1.動態函式庫可以不斷被利用,執行檔會比較小 但在執行時,執行檔和函式庫都要有,否則程式執行失敗 2.靜態函式庫在編譯的同時也將函式庫一同編譯進去,所以執行檔檔案較大(.a) ``` ### 每年必考 ```bash . 當前目錄下的檔案跟目錄 .. 上一層目錄下的檔案跟目錄 cd ../../tmp 他不是只能往上,也可以往下 往上到home -> 往上到/ -> 往下移到tmp - cp -r dir1 /tmp/將一個目錄全部複製至目的地 -r (recursive) ->將dir1目錄全部複製至tmp ``` ## # chapter 03 ## 老師的上課筆記 這裡大部分是老師上課的內容,我直接打字記錄下來,沒有多加整理。 ### 0418上課筆記 #### 進階檔案處理 ```bash hard link (hlink) 硬連結 symbolic link (slink) 符號連結 跟windows下的捷徑很相似,但不完全一樣 Windows可以連結到任意地方的檔案或是資料夾! - Linux檔案系統 目前CentOS7 用的是 XFS 早期則是 EXT2 EXT3 EXT4 - XFS(64位元日誌行檔案系統) EXT3 跟 EXT2 主要差異在日誌功能 ->為了節省掃描整顆硬碟所耗費的時間 EXT4 和 EXT3則是 ->突破檔案系統的大小限制 ->使用Extent file writing(範圍性寫入檔案),減少檔案在寫入磁碟時的游離區塊 - Windows檔案系統 FAT16 FAT32 NTFS EXFAT - inode (檔案資訊紀錄系統) 用來描述真正資料的資料 假設有一個檔案a.txt a.txt的inode用來描述真正檔案的資訊 像是檔名、更動時間、權限與檔案儲存的區塊位置 ``` #### Slink vs hardlink(期末考必考!!) ```bash 符號連結(symbolic link) 產生兩個不同的indoe,如果原始檔案消失,則鏈結無效 ln -s date slink 產生符號連結slink,slink指向data echo "hi" > data cat data = cat slink 不能變動其屬性,但如果我們去更動,原始檔案的屬性會改 檔案資訊開頭為 l (link) 增加新的連結,原始檔案的連結次數不變 可以跨分割區,可以支援目錄 - 硬連結(hard link) 如果原始檔案消失,鏈結還是有效 (因為hlink和原始檔案的indoe是共用的,所以即使原始檔案刪除,仍然可以指向該檔案) 可以變動其屬性 增加新的連結,原始檔案的連結次數加一 不可以跨分割區,不可以支援目錄 echo hello > data ln data hardlink ``` #### 指令教學 ```htmlmixed ls -i #可以列處檔案的inode - ls -l #在看屬性的時候只能看到Modify time #如果想看其他的屬性要用 stat a.txt #來查看完整的檔案屬性 - which #用來找尋執行檔所在位置 which #passwd 找尋passwd執行檔所在位置 - su - #tom 使用者切換 - chmod 666 a.txt #變更屬性 - timedatectl set-timezone Asia/Taipei #調整時區 ntpdate tock.stdtime.gov.tw #時間校正 - file a.sh file /usr/bin/passwd #用於判斷檔案類型的工具,它可以分析檔案的二進位內容,並試圖猜測檔案的類型 #用來幫助我們確定檔案類型,從而選擇正確的應用程式來打開或處理該檔案或者進行格式轉換等操作 - ``` #### Linux的執行檔 ```htmlmixed #在linux中只要該檔案具有可執行的權限,任何檔案都可以是執行檔,即使是文字檔也一樣 #執行檔按時,前面記得加一個 "./" (保護系統安全) #如果希望直接輸入檔名就可以執行執行檔 #可以參考以下2個方式 *環境變數 *gedit .bashrc - #產生一個大型的測試檔案 dd if=/dev/zero of=3M bs=1M count=3 ls -l -h #將檔案大小轉換成我們熟悉的格式 df -h #查看磁碟的使用空間 df -h | egrep / df -h | egrep /$ 以斜線為結尾 df -h | egrep /$ | awk '{print $5}' df -h | egrep /$ | awk '{print $5}' | tr "%" "" 把%去掉 ``` #### 重點內容(題外話) [相關資訊](https://dywang.csie.cyut.edu.tw/dywang/linuxsecurity/node39.html) ``` s ->在執行的過程中,短暫擁有最高權限,執行結束後恢復最初權限 檔案的特殊屬型 - SBIT(Sticky Bit) 典型的例子如 /tmp 的權限是 『drwxrwxrwt』,任何用戶都可在 /tmp 內新增、修改檔案 但僅有該檔案/目錄建立者與 root 能夠刪除自己的目錄或檔案。 - Acess time :代表存取,只要讀某個檔案,那個檔案的存取時間就會修改 Modify time :代表改變內容 change time : 除了內容改變會變動外,屬性變動也會變更時間 ``` ## 個人筆記 這裡則是我參照課本的內容,自行整理的重點。 ### 符號連結與硬連結的不同 | 功能 | 符號連結 | 硬連結 | | -----------| ---------- | ---------| | 跨越分割區 | O | X | | 支援目錄 | O | X | | 目的地刪除後 | 無效連結 | O | | 權限 | 無法自訂,依目的地檔案或目錄權限| 可自訂權限| ### 檔案資訊記錄檔-inode <details> <summary>範例程式碼</summary> touch file1 file2 ls -i - 輸出結果: 1178618 file1 1178619 file2 </details> ```mermaid graph LR A[存取檔案] --> B[inode] B --> C[檔案資訊] B --> D[區塊位置] D --> E[磁碟區塊] ``` ### 連結 #### 符號連結 指令格式:`ln -s 目標對象 連結名稱` <details> <summary>建立符號連結</summary> echo "hello" > data ls -l data ln -s data slink ls -l - 輸出結果: -rw-r--r--. 1 root root ... data lrwxrwxrwx. 1 root root ... slink > data - cat slink - 輸出結果: hello 這樣符號連結就算建置成功!! </details> -- 這邊可以看到符號鏈結後面會指向data這個真實檔案 且還有一個重點是它的權限為`l(link)rwxrwxrwx` <span style="color:red">**但這並不是代表所有人都有讀寫與執行的權力,而是代表符號連結沒有自己的權限,其權限是以真實檔案為主。**</span> <details> <summary>無效的符號連結</summary> rm data ls -l slink </details> -- 輸出結果: lrwxrwxrwx. 1 root root ... <span style="color:red"> slink </span> > data **(slink檔案變成紅色警示,代表該連結無效)** 其原因可以參照下列示意圖 ```mermaid graph LR A[符號連結<br>/root/slink] --> B[inode<br>#28123] B --> C[文字檔<br>/root/data] C --> D[inode<br>#23050] D --> E[檔案區塊] ``` 所以當data被刪除後,`inode #28123` 就會指向空檔,從而發生錯誤 <details> <summary>刪除符號連結</summary> rm slink </details> #### 建立硬連結 指令格式:`ln 目標對象 連結名稱` <details> <summary>建立硬連結</summary> echo "hello" > data ln data hlink ls -l - 輸出結果: -rw-r--r--. 2 root root ... data -rw-r--r--. 2 root root ... hlink - cat hlink - 輸出結果: hello 這樣硬連結就算建置成功!! </details> -- 這邊可以看到data檔案的第二個欄位由1變成了2,代表建立硬連結時,是把原data檔案的整個inode資料複製一份給hlink,所以即使刪除了目標檔案,硬連結仍可以正常得到檔案的內容。 ```mermaid graph LR A[符號連結<br>/root/slink] --> B[inode<br>#23050] C[文字檔<br>/root/data] --> B[inode<br>#23050] B --> E[檔案區塊] ``` <details> <summary>建立硬連結時的限制</summary> 1.不可跨越分割區 ln /var/log/messages /home/user/hlink 輸出結果: ln: failed to create hard link Invalid cross-device link 2.不可使用於目錄 mkdir projects ln projects hlink 輸出結果: ln: ‘projects’: hard link not allowed for directory </details> -- 硬連結不可跨越分割區以及不可使用於目錄 ### 搜尋特定檔案 -find [參考網站](https://blog.gtwang.org/linux/unix-linux-find-command-examples/) 1. 在指定位址搜尋指定名稱的檔案 ```shell find /home -name tom.txt ``` 2. 在指定位址搜尋指定名稱的檔案(不分英文大小寫) ```bash! find /home -iname tom.txt ``` 3. 指定檔案類型 利用`-type`這個參數指定檔案的類型 `d` 代表directory `f` 代表file `l` 代表link ```bash! find /usr/ -type f ``` 4. 特定檔案大小 ```bash! #搜尋大於5MB的檔案 find /usr/ -size +5M ``` 5. 特定時間點之後 ```bash! #搜尋近12天來更動過的檔案 find /root -ctime -12 ``` 6. 搜尋指定時間後的更新檔 ```bash! #搜尋變動時間在/root/timebase1之後的檔案 find /root -cnewer /root/timebase1 ``` # chapter 04 ## 0502上課筆記 ### 通配符vs正則表達式 [參考網站](https://bpdocs.blueprism.com/bp-7-1/zh-hans/helpWildcardsAndRegex.htm) ```bash 通配符 -用來匹配檔案名稱 - * 代表0個或是很多個任意質或是任意字母 - ? 代表一個字符 - # 表示一個數字 用法: ls a* ______________________ 正則表達式 -針對內容進行匹配 最簡單的用法: grep "a" a.txt grep "a*" a.txt -> *代表重複前面的字母零次或多次 ?代表重複前面的字母零次或一次 +代表重複前面的字母一次或多次 _____ ``` ### Linux篩選內容(grep) [參考網站](https://blog.gtwang.org/linux/linux-grep-command-tutorial-examples/) ```bash Linux 三劍客 awk / grep / sed - grep "關鍵字" file1 file2 可以用來匹配檔案名稱以及檔案內容 - 檔案內容: Ex 1: grep network /etc/*.conf 在etc底下尋找結尾是.conf且檔案內容符合network的檔案 - Ex 2: grep -n network /etc/*.conf -n 顯示他所在位置是第幾行 _____ 檔案名稱: Ex: ls /etc/ | grep nfs == ls /etc/nfs* - 參數: 1. -i 不分大小寫 2. -n 標示行號 3. -v 反向匹配,亦即除了他以外其他都要 4. -r 遞迴搜尋所有檔案 5. -A 1 After 顯示他下面的一行(數字可以改) 6. -B 1 Before 顯示他前面的一行(數字可以改) 7. ^ 匹配字符必須出現在開頭 8. $ 匹配字符必須出現在結尾 ``` ### 補充a.txt內容 ``` ABC aBc Abc aaa aa2c abb acc bb cc ``` ### 上課小程式 ```bash 1. grep -v 範例小程式 ps -ef | grep sleep ps -ef | grep sleep | grep -v grep 2. \grep "ABC" a.txt \恢復原本的指令,alias顏色指令被關閉 3. cat a.txt |grep "^A" 顯示開頭為大寫A 4. cat a.txt |grep "^a" 顯示開頭為小寫a 5. cat a.txt |grep "^[aA]" 顯示開頭為大寫A或小寫a 6. cat a.txt |grep "A[bB]C" 輸出結果: ABC 或 Abc都可 7. cat a.txt |grep "a[0-9]c" 輸出結果: a2c a3c a4c ..... 8. 使用指令顯示系統中DNS server IP位址 ``` ### 上課小重點 ```bash 密碼資訊會存放在shadow檔裡面 cat /etc/shadow | grep "root" 系統帳號 /root:/sbin/nologin ->sell會顯示不能登入 避免顯示系統帳號 cat /etc/shadow | grep "^root" 行數統計(wc -word count) cat /etc/passwd | grep -wc "nologin$" 把空白行顯示出來 cat a.txt | grep -n "^$" 把配置檔的註解和空白行拿掉 -v cat sshd_config |grep -v "^#" | grep -v "^$" 小陷阱 cat a.txt | grep "^ab*" 顯示結果: aBc aaa aa2c abb acc -> b*重複0次的結果,所以不一定會有b,只要開頭是a就行 +的使用,寫錯可能會造成系統看不懂 1. cat a.txt | grep "^ab+" (錯誤) 2. cat a.txt |egrep "^ab+" (正確) ``` ### 文字化編輯器 ```bash vim test.c 按下 i、o、a 開始編輯 編輯完成後如果想儲存 1. 先按下esc跳回一般模式 2. 再輸入 :wq 儲存並離開 !!如果權限不夠導致無法儲存修改內容 可以輸入:q! 放棄儲存強制離開 ``` ### 新增硬碟的完整過程 待完成 # chapter 05 ## 0509上課筆記 ### 格式化usb [參考網站](https://earthcat99.pixnet.net/blog/post/36811189) FAT32 ```bash 以virtualBox的操作方式為主!! USB driver : if it is FAT32 just plug into linux system. It can identify the usb drive. Linux can also mount automatically. 1. 將隨身碟格式化成FAT32 2. 裡面準備一個hi.txt檔 3. 在virtualBox工具列上找到device -> usb ->usb名稱 4. 利用 df -h 或 dmesg | grep sdc這個指令查看隨身碟所在路徑 5. cd 隨身碟所在路徑 6. touch生成檔案 ---------------------------------------- 如果無法自動掛載,可以採用以下方式 1. cd / 2. mkdir myusb 3. mount /dev/sdb/myusb 4. cd /myusb 5. ls 如果還是不行就在電腦上找檔案總管,用圖形化介面吧 ----------------------------------------- 如果想要退出usb的話: cd 一定要記得先離開才可以umount umount 隨身碟所在路徑 device -> usb -> 將usb的勾勾按掉即可 ----------------------------------------- 這裡要注意的是,上述所寫的sdb都是基於目前我的電腦的狀態來做操作 其狀態也有可能是sdc sdd .... 所以建議在操作前可以先用 df -h 這個指令查看自己目前的硬碟狀態 ``` NTFS [參考網址](https://it001.pixnet.net/blog/post/328444228) ```bash 1. 怕有複製問題,可以先連上PUTTY,或使用虛擬機瀏覽網頁進行複製 2. 輸入指令 wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz 3. 解壓縮 tar 4. 進行編譯 mkdir myusb mount -t ntfs -3g /dev/sdc /myusb ``` ### 帳號管理 ```bash' 很重要!!!有可能會考!! etc 下的 password 裡面沒有存放任何密碼,裡面存放的是一般使用者帳號跟系統帳號 密碼都是存放在 /etc/shadow裡面 系統管理者叫做root 他的uid=0 一般使用者的uid是從1000開始 ``` ### John the Ripper 破解密碼 這邊我使用的是Kali Linux來操作 操作方法可以參考[這篇文章](https://ithelp.ithome.com.tw/articles/10300529) ```bash 首先先進行遠端連線 ssh username@ip位置 接者切換成超級使用者,然後輸入以下指令 cat /etc/passwd /etc/shadow > passwd.txt cat passwd.txt 接著就可以選擇看是利用複製貼上的方式直接複製在本機上,或是利用scp的方式遠端下載檔案 scp username@ip位置:想獲取的檔案位置 本地端想儲存的位置 scp root@192.168.X.X:/root/passwd.txt /home/kali ls 就可以看到passwd.txt已經被我們下載好 破解: # 格式:john --wordlist=[你要遍歷的密碼檔] --format="[解什麼樣的加密法]" [欲解密的檔案] john --wordlist=/usr/share/wordlists/rockyou.txt --format="crypt" passwd.txt 然後就靜靜等待其破解完成 然後可以輸入以下指令查看完整的破解信息 john --show passwd.txt ``` ## 個人筆記 ``` /etc/passwd存放著所有的帳號資訊,而每一列帳號分別隱藏著7項資訊 如下所示: jack:x:500:500:jack:/home/jack:/bin/bash 帳號名稱:密碼:帳號編號UID:所屬群組編號GID:註解:家目錄:登入時使用的shell 這邊有一個小重點在結尾的/bin/bash這邊下面會提到 ``` ### 停止帳號登入 ```bash! 1. 修改/etc/passwd 中帳號的密碼欄位 vi /etc/passwd (將原本的x改為!後存檔離開) 2. 利用chsh(change shell)指令改變帳號的shell chsh tom /sbin/nologin ``` ### useradd 指令規格 指令用法`useradd [option] username` #### 建立新帳號並指定在已存在的群組 ```bash! groupadd rd useradd -g rd eric id eric - 輸出結果: uid=503(eric) gid=501(rd) groups=501(rd) ``` #### useradd 指令常用選項 | 選項用法 | 說明 | | -------- | -------- | | -c | 帳號的註解及說明 | | -g | 指定帳號的主要群組 | | -G | 指定帳號所屬的附加群組 | | -d | 指定家目錄 | | -e | 設定帳號的使用到期日 | | -u | 指定帳號的UID | `UID (User ID)` 、`GID (Group ID)` #### 指定附加群組 ```bash! groupadd manager useradd -g rd -G manager eric id eric - 輸出結果: uid=503(eric) gid=501(rd) groups=501(rd),504(manager) ``` #### 刪除帳號 ```bash! userdel eric 這邊須注意,如果指令沒有加上任何參數,原先帳號的家目錄並不會被刪除 如果想要一併刪除帳號的家目錄所有檔案,可以使用下列指令 userdel -r eric ``` #### 變更帳號資料 指令`usermod` ```bash! # 為tom新增附加群組 usermod -G manager,sales tom id tom ``` #### usermod 指令常用選項 | 選項用法 | 說明 | | -------- | ---------------------- | | -c | 改變帳號的註解及說明 | | -g | 改變帳號的主要群組 | | -G | 改變或增加帳號所屬的附加群組 | | -d | 改變家目錄 | | -l | 變更原帳號的名稱 | | -e | 改變帳號的使用到期日 | | -u | 改變帳號的UID | #### 刪除群組以及查詢使用者的群組 ``` groupdel rd groups tom ``` ### 檔案權限 整個權限值共有10個字母,第一個是檔案類型,第二到第十個則分成三組,如下所示。 ```mermaid graph TD A[rwx<br>擁有者權限] B[rwx<br>群組權限] C[rwx<br>其他人權限] ``` * r 可讀(cat),但不能修改 * w 可寫可新增可修改可刪除 * x 可執行 * -- 不允許該權限 #### rwx的數字表示法 * r =4 * w = 2 * x = 1 ``` 範例: rwxr-xr-- 將其切分為三個區快 1. rwx = 4+2+1=7 2. r-x 4+0+1=5 3. r-- 4 因此此檔案的權限為754 ``` | 數字表示法 | 權限 | |:----------:|:-----:| | 0 | - - - | | 1 | - - x | | 2 | - w - | | 3 | - w x | | 4 | r - - | | 5 | r - x | | 6 | r w - | | 7 | r w x | #### 變更檔案權限 ```bash a u g o rwx rwx rwx 擁有者 群組 其他人 權限 權限 權限 - # 為擁有者(u)加上X的權限 chmod u+x file # 為擁有者(u)及群組(g)加上X和r的權限 chmod ug+rx file # 為所有人增加權限 chmod a+r - 如果想要移除權限把'+'改成'-'就行了 如果出現'='則表示不論原本權限為何,一律改變為=後的權限 chmod g=rx file 也可以用','合併兩個權限修改 chmod u+x,g+wx myfile ``` #### 變更檔案擁有者 指令`chown 使用者帳號 檔案或目錄` #### 變更檔案擁有群組 ```bash chown 使用者帳號.群組 檔案或目錄 chown 使用者帳號:群組 檔案或目錄 - # 也可以只改變檔案的群組,但不改變擁有者 chown .群組 檔案或目錄 chgrp 群組 檔案或目錄 ``` ### 目錄權限 * r 可以列出該目錄的檔案清單(ls) * w 至該目錄中的檔案與目錄都可以異動,如寫入、建立刪除與更名檔案與目錄 * x 可進入該目錄中(cd) * -- 不允許該權限 # chapter 06 ## 0516上課筆記 ```bash mkdir -p 目錄名稱: 加上-p,如果資料夾不存在,則創建資料夾,如果資料夾存在,則不動作,也不會有錯誤發生 -d 看資料夾本身的屬性 -l 看資料夾本身的內容 chmod u-r dirname 擁有者將資料的可讀權限拿掉 chmod u-w dirname 控制檔案的新增、刪除、修改裡面的檔案內容 如果目錄權限沒有w,就無法刪除檔案....但這只是對一般使用者,管理者還是可以照常刪除 ``` # chapter 07 ## 0523上課筆記 Linux 細部權限 ACL(Acess Control List) [上課補充](https://ithelp.ithome.com.tw/articles/10221185) ```bash su + 使用者名稱 -> 切換使用者 (切換後保持在當前目錄) 注意! 這邊中間不要加' - '會切回使用者的家目錄 ``` ## 個人筆記 ```bash 行程狀態指令 ps -f (詳細資訊) 活用行程列表 ps aux|more 搜尋特定服務的狀態 ps aux | grep crond 顯示行程的nice值 ps l 顯示特定欄位 ps o comm,pid,ni - 背景程式 sleep 60 & 或 bg指令將目前正在執行的程式丟到背景 ctrl +Z 將前景行程stop 觀察背景與前景行程 jobs 將背景行程取回前景 fg - 指定優先權值 nice -n -3 sleep 60& 調整優先權值 renice nice值 PID - 刪除行程 kill PID or kill -9 PID(Process ID) ``` ## # chapter 08 ## 0530 上課筆記 ```bash NTP (Network time protocol) time synchronization(簡稱sync) 1.時間同步 - 調出歷史紀錄 history ``` ## 個人筆記 ### 防火牆 ```bash 1. 防火牆狀態 firewall-cmd --state 2. 列出目前已設訂的zone(所在地區)firewall-cmd --get-active-zone 3. 列出zone的詳細資訊 firewall-cmd --zone=public --list-all 4. 列出所有可懸zone firewall-cmd --get-zones 5. 啟用zone firewall-cmd --zone=home --change-interface=ens0s3 6. 如果想要寫入設定檔可以加上 --permanent firewall-cmd --permanent --zone=home --change-interface=ens0s3 7. 重新讀取設定檔 firewall-cmd --reload 8. 列出所有可使用的service firewall-cmd --get-services 9. 加入service firewall-cmd --zone=public --add-services=dns 10.加入port firewall-cmd --zone=public --add-port=9958/tcp ``` ### 壓縮檔案-備分 #### 壓縮檔案 -gzip ```bash gzip file ``` #### 解壓縮gz檔 -gunzip ```bash # gunzip指令可將.gz的壓縮檔解開 gunzip file.gz ``` #### 壓縮檔案 -zip ```bash zip -r testfile.zip testfile # -r 可以指定壓縮後的檔案名稱 ``` #### 解壓縮檔案 -unzip ```bash unzip testfile.zip ``` #### 包裹多個檔案 -tar ```bash # -c 產生新的包裹檔案 # -v 觀看指令進度 # -f 指定包裹檔案的名稱 tar -cvf fileall.tar file1 file2 file3 # 也可以利用*指定多個符合的檔名 tar -cvf fileall file* # 打包整個目錄 tar myetc.tar /etc ``` #### 解壓縮檔案 -tar ```bash tar -xvf fileall.tar #列出包裹檔裡的檔案清單 tar -tvf fileall.tar ``` #### 打包成.tar.gz檔 ```bash # 先打包成tar檔,再打包成gz檔 tar myetc.tar /etc gzip myetc.tar # 加上-z指令 tar -czvf files.tar.gz file* ``` #### 解壓縮.tar.gz檔 ```bash tar -xzvf files.tar.gz ``` #### bzip2 & bunzip2 ```bash # 壓縮 bzip2 file1 # 解壓縮 bunzip2 file1.bz2 ``` ### 設定系統時間與時區 #### date指令 ``` date +%Y%m%d ``` | 參數 | 意義 | 參數 | 意義 | | ---- | ---- | --- | --- | | %Y | 年分 | %H | 時 | | %m | 月份 | %M | 分 | | %d | 日 |%S | 秒 | ```BASH # 格式MMDDhhmmYYYY # 2017年1月5日 早上10點整 date 010510002017 ``` | 參數 | 意義 | | ---- | ---- | | MM | 月份 | | DD | 日期 | | hh | 小時 | | mm | 分鐘 | | YYYY | 西元年 | #### 產生以日期為檔名空白檔案 ``` touch `date +%Y%m%d` # 再備分檔的檔明中註明日期 tar -cvfz etc-backup-`date +%Y%m%d`.tar.gz /etc ``` ### XFS的磁碟配額工具-xfs_quota ```bash # 產生磁碟配額表 -h 顯示單位 xfs_quota -xc 'report -h' /home # 列出磁碟使用情形 xfs_quota -xc 'free -h' /home # 列出某群組或某使用者的使用情形 xfs_quota -xc 'quota -h jack' /home ``` ### 設定使用者配額 ```bash # 使用者可以寫入10m的空間,最多12m xfs_quota -xc 'limit bsoft=10m bhard=12m jack' /home #磁碟配額設定簡單化 setquota -u jack 10000 12000 0 0 /home #10MB #12MB # 複製配額給另一個user edquota -p tom jack #來源帳號 #目標帳號 ``` ### 使用者配額報表 ``` repquota -au ``` ### 群組配額報表 ``` repquota -ag ```

    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