--- tags: LSA, 1091 --- LSA week4 === [TOC] # Password - 更改方式 ``` passwd passwd -S #密碼狀態 passwd -aS ``` :::info **# passwd -S 欄位對應** 1. 帳號名稱 (對應 /etc/passwd) 2. 密碼狀態,狀態包含鎖定密碼(L)、無密碼(NP)與可用密碼(P)。 3. 上次修改密碼的時間。 4. 密碼最短使用期限(minimum password age),單位為天。 5. 密碼最長使用期限(maximum password age),單位為天。 6. 密碼過期前警告期間(password warning period),單位為天。 7. 密碼過期後可使用的期間(password inactivity period),單位為天。 ::: :::success 一般而言,為了讓系統能夠順利以較小的權限運作,系統會有很多帳號, 例如 mail, bin, adm 等等。而為了確保這些帳號能夠在系統上面具有獨一無二的權限, 一般來說 Linux 都會保留一些 UID 給系統使用。在 FC4 上面,小於 500 以下的帳號 (UID) 即是所謂的 System account。 ::: - passwd 實際運行的儲存方式 (s 升權) - `s` 執行的時候是檔案 owner 的權限 (setuid 權限) - `S` setgid 權限 - 一個普通帳號執行 passwd 修改自己的密碼時, 其實是用 root 身份修改系統內的密碼檔 ```shell= $ ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd ``` :::success 先找尋 /etc/passwd 裡面是否有這個帳號?如果沒有則跳出,如果有的話則將該帳號對應的 UID ( User ID )與 GID ( Group ID )讀出來,另外,該帳號的家目錄與 shell 設定也一併讀出; 再來則是核對密碼表啦!這時 Linux 會進入 /etc/shadow 裡面找出對應的帳號與 UID,然後核對一下你剛剛輸入的密碼與裡頭的密碼是否相符? 如果一切都 OK 的話,就進入 Shell 控管的階段囉 ::: - `/etc/shadow` 中是經過編碼後的密碼,需要 root 權限 ![](https://i.imgur.com/KK2x9ud.png) - `/etc/group` ![](https://i.imgur.com/8US6Pn1.png) - `/etc/passwd` - 帳號名稱 - 密碼(x) - UID - GID - 使用者資訊 - 家目錄 - shell ![](https://i.imgur.com/YDKVfSk.png) ![](https://i.imgur.com/GTmaNRf.png) ## uid 與 gid :::success **uid 與 gid 的作用** username 只是一個代稱 實際存取權限是透 uid 與 gid 來辨別 ::: 指令查看方式 ```shell= id {username} ``` ![](https://i.imgur.com/HP4rigQ.png) ![](https://i.imgur.com/fwqTvsq.png) # apt, aptitude ## apt :::info APT ( Advanced Package Tool ) 最早是由 debian 這個 distribution 所發展出來的 APT 主機可以將已經存在的 RPM 檔案進行分析,並且將各個套件的相關係記錄下來 ::: - `apt-get` ![](https://i.imgur.com/UdU8yCJ.png) - `apt-cache` ![](https://i.imgur.com/8bvLYcW.png) - `apt update` 更新 source list (/var/lib/apt/lists/) - ![](https://i.imgur.com/bnIEDY8.png) - `apt upgrade` - `sudo apt dist-upgrade` 查詢可以更新的套件 ## aptitude :::info Aptitude是個涵蓋apt-get,apt-cache...等的文字介面前端程式。 可以使用它來取代apt-get的相關操作。 ::: - 會自動執行 update - 解決相依性 - 圖形化界面 # vim, vi, nano ## 安裝教學 ``` sudo apt install -y vim ``` ## 逃離教學 1. 瘋狂按 `esc` 2. 按 `:` 3. 按 `q` , 如有必要加上 `!` ## 使用教學 1. 純打開 `vim` 2. 打開或新增一檔 `vim <filename>` ## mode ### command mode |說明|按法| |---|---| |cursor moving|hjkl or arrow keys| |jumping to|num G, :num| |delete line|dd| |delete word|dw| |delete current char|x| |delete previous char|X| |paste after|p| |paste before|P| |copy line|yy| |forward search|/| |backward search|?| |repeat previous search|n| |repeat previous search but in opposite|N| |search and replace|:num1, num2 s/pat/replaced/| |from first line to last line|:1,$ s/buffer/BUF/| |from current line to last line|:.,$ s/money/Money/| ### Insert Mode |說明|按法| |---|---| |insert before|i| |append after|a| |insert at the beginning of the line|I| |append to the end of the line|A| |a new line after|o| |a new line before|O| ### File |說明|按法| |---|---| |save|:w| |save to fn|:w fn| |quit|:q| |save and quit|:wq| |save to fn and quit|:wq fn| |save and quit|zz| |read a file(the content of fname will be inserted below current line)|:r fname [參考資料](http://erdos.csie.ncnu.edu.tw/~klim/unix-intro/unix-981/vi-summary.html) ## 我有用的參數 |說明|指令| |---|---| |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 ## 正規表示法 ### 基本語法 |字元|說明| |---|---| |\||代表選擇| |+|代表前面的字元必須至少出現一次| |?|代表前面的字元最多只可以出現一次| |\*|代表前面的字元可以不出現,也可以出現一次或者多次| |()|可以用來定義運算子的範圍和優先度| |^|符合輸入字串的開始位置| |$|符合輸入字串的結束位置| vim 練習指令: vimtutor 神奇指令::w !sudo tee % [練習網站](https://regex101.com/) [視覺化練習網站](https://ihateregex.io/playground) [參考資料](https://zh.wikipedia.org/zh-tw/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F) # ifconfig ![](https://i.imgur.com/TcC4v0X.png) ## 網域分割 ### 網路等級 - ip 開頭 ![](https://i.imgur.com/YdycxKt.png) - 預設 Net Mask - A Class 的 mask 是 255.0.0.0 - B Class 的 mask 是 255.255.0.0 - C Class 的 mask 是 255.255.255.0 ### 算 Net ID and Host ID - IP 和 Net mask 加以 AND 運算得到 Net ID - 先將 Net Mask 做一個 NOT 運算,然後再和 IP 做一次 AND 運算可以得到 Host ID ### Sub-net ID :::info Sub-net Mask 就是從左往右的按需要將本來屬於 Host ID 的一些連續的 bit 轉為 Sub-net ID 來使用 ::: ### CIDR (Classless Inter-Domain Routing) [參考資料](http://www.study-area.org/network/networkfr1.htm) # host, DNS ## DNS (Domain Name Service) - DNS 是啥 - - DNS 查找流程 :::info 在整個 DNS 系統的最上方一定是 . (小數點) 這個 DNS 伺服器 (稱為 root),最早以前它底下管理的就只有 (1)com, edu, gov, mil, org, .net 這種特殊領域以及 (2)以國家為分類的第二層的主機名稱了! ::: ![](https://i.imgur.com/dfFgJ1F.png) - 電腦查找 DNS 流程(根據 /etc/nsswitch.conf 設定) 1. `/etc/hosts/` 網路名稱, 保存有 host 跟 IP 的對應 2. `/etc/resolv.conf` (DNS server) ![](https://i.imgur.com/k4HRMte.png) 3. `/etc/hostname` ## hostname :::info 設定 hostname 會把 hostname 設到 hosts ,dns 查詢會先看 hosts ,才往上問,如取跟外界一樣,就會連到自己 ::: - 更改 hostname (用指令) - `hostnamctl set-hostname {hostname}` 使用基本指令更改 hostname - 登入與登出 - `sudo login` - `exit` # [網路分層概念](https://hackmd.io/@ncnu-opensource/book/%2FA7_wEpjMSTiLAfKJJHYpug?type=book) # nginx