Im-Tim-mI
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
# 鳥哥期中考 --- # 繳交 ``` vim ~/ans.txt touch ../home/student/ans.txt #創建文件 vbird_book_setup_ip #設定IP、學號 vbird_book_check_unit #上傳作業 ``` vim ``` :set nu. #顯示行號 :set nonu. #取消行號 ``` # 1.系統救援 問題: 因為某些緣故,目前這個作業系統應該是無法順利開機的。 思考: 根據猜測,可能的原因與 (1)管理員曾經動過 chsh ,(2)管理員似乎也更動過 fstab 這個設定檔。 救援: 請依據這些之前的可能舉動,來恢復系統的可登入狀態。 提醒注意: 千萬不要忘記 .autorelabel 的動作! 成功開機登入後: 順利登入系統後,再使用 root 身份處理 ```vbird_book_setup_ip``` 的腳本設定。 ![image](https://hackmd.io/_uploads/Sy3096dlA.png) 按傳送按鈕 按ctrl+Alt+del ![image](https://hackmd.io/_uploads/S1jbi6_lC.png) 到這畫面之後按E 進入編輯模式 ![image](https://hackmd.io/_uploads/B1eVjpOgC.png) 在 quiet 後加 ```rd.break``` 之後按 ctrl+x ![image](https://hackmd.io/_uploads/HkWrjTOeA.png) 到這畫面輸入 ```mount -o remount,rw /sysroot``` (重新掛載文件系統) ```chroot /sysroot``` ![image](https://hackmd.io/_uploads/S1vpspOgA.png) 輸入```vim /etc/fstab```按i進入編輯畫面 修改/dev/mapper/cebtos-home /home xfs defaults,noAtime 改成noatime,按ESC退出編輯模式,再輸入:wq儲存加退出 ![image](https://hackmd.io/_uploads/HyGbdRdlR.png) ```mount -a```測試掛載 ```touch /.autorelabel```創建空文件 (SELinux 的標記恢復服務) ```exit```離開 按傳送按鈕 按ctrl+Alt+del --- # 2.管理員的操作環境整理: --- (底下的動作每次登入都可以生效,須修改設定檔喔!) A.當你用 student 轉成 root 之後,會發現很奇怪的現象,就是很多指令都不能執行了。 這應該與上次登入管理員的用戶處理到錯誤的 bash 環境設定檔有關。請查詢 root 可能的設定檔後,將這個問題解決。 B.增加 histroy 的輸出,讓 root 自己最大可達 10000 筆紀錄,且 (1)其他用戶保留預設值 (2)紀錄檔內也要紀錄 10000 筆。 C.建立一個命令別名 myerr 這個指令,這個指令會運作『 echo "I am error message" 』這個指令串。 D.當 root 執行『 cd ${mywork} 』時,工作目錄會跑去 /usr/local/libexec/ 當中 ```cd```(回到用戶家目錄) 編輯```vim .bashrc```添加環境變數PATH 或使用```vim ~/.bashrc``` 最尾端添加 ``` PATH="${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" ``` 中斷添加 ``` HISTSIZE = 10000 HISTFILESIZE = 10000 alias myerr = 'echo "I am error message"' mywork="/usr/local/libexec" ``` 儲存退出後執行 ``` source ~/.bashrc ``` (立刻應用修改) ![image](https://hackmd.io/_uploads/S1YxVVKxR.png) 疑惑,似乎 ![image](https://hackmd.io/_uploads/ryRdQ4Fe0.png) 要刪除,參考學長資料 ![image](https://hackmd.io/_uploads/rJCfOmFgC.png) A.環境變數 ``` PATH="/bin:${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/root/bin" ``` ``` vim ~/.bash_profile ``` 也要添加環境變數 ``` PATH='/bin:${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/scripts' ``` 疑惑要刪除 ![image](https://hackmd.io/_uploads/BkO9nXFeR.png) 改成 ![image](https://hackmd.io/_uploads/B1jkTQKlR.png) 與學長筆記簿不同處 ``` vim ~/.bash_profile 在PATH=' '輸入/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/root/bin ``` # 3.檔案系統的整理: A.系統內有個名為 /dev/vda4 (或 /dev/sda4) 的分割槽,這個分割槽是做錯的,因此,請將這個分割槽卸載, 然後刪除分割,將磁碟容量釋放出來。 B.完成上面的題目之後,請依據底下的說明建立好所需要的檔案系統(所有的新掛載,應該使用 UUID 來掛載較佳。) 容量 檔案系統 掛載點 掛載額外參數 1GB XFS /mydata/xfs nosuid 2GB VFAT /mydata/vfat uid均為student 1GB EXT4 /mydata/ext4 noatime 1GB swap - - 上述四個新增的資料都能夠開機後自動的掛載或啟用。 C.有個光碟映像檔 /mycdrom.iso 的檔案,請將他掛載到 /mydata/cdrom 裡面,而且每次開機都能自動掛載上來。 (請自行查詢光碟檔案掛載時所需要的檔案系統類型) D.建立一個名為 /mydata.img 的 200MB 大檔案,這個檔案格式化為 xfs ,且開機會主動的掛載於 /mydata/xfs2/ 目錄中 A. ``` umount /data #卸載已經掛載的文件系統 mkdir /mydata #創建一個新的目錄 mkdir /mydata/xfs #創建一個新的目錄 mkdir /mydata/vfat #創建一個新的目錄 chown student /mydata/vfat #更改檔案或目錄的擁有者可不打 chgrp student /mydata/vfat #更改檔案或目錄的群組可不打 mkdir /mydata/ext4 #創建一個新的目錄 fdisk /dev/vda #開啟管理磁盤分區的工具 p #查看所有掛載的硬碟 d #刪除磁碟分區指令 4 #刪除磁碟分區4(vda4) p #查看掛載的四號硬碟分區是否刪除 ``` 添加四個容量的硬碟 容量 檔案系統 掛載點 掛載額外參數 1GB XFS /mydata/xfs nosuid 2GB VFAT /mydata/vfat uid均為student 1GB EXT4 /mydata/ext4 noatime 1GB swap - - ``` n #添加磁碟分割 4 #號分區 #直接Enter +1G #沒打+會不認G只能辨識數字 y #確認分割 n #添加磁碟分割 5 #號分區 #直接Enter +2G #沒打+會不認G只能辨識數字 y #確認分割 n #添加磁碟分割 6 #號分區 #直接Enter +1G #沒打+會不認G只能辨識數字 y #確認分割 n #添加磁碟分割 7 #號分區 #直接Enter +1G #沒打+會不認G只能辨識數字 y #確認分割 p #查看所有掛載的硬碟 w #離開 mkfs.xfs /dev/vda4 #格式化成XFS mkfs.vfat /dev/vda5 #格式化成VFAT mkfs.ext4 /dev/vda6 #格式化成EXT4 mkswap /dev/vda7 #指定分區或文件為交換(swap)區域的命令 blkid /dev/vda{4,5,6,7} #查詢UUID vim /etc/fstab #編輯自動掛載分區文件 #把找到的UUID貼最下面進去 #需要調整格式 /dev/vda4 /data xfs defaults 0 0 #需要刪除 ``` ![image](https://hackmd.io/_uploads/SyOBi4tg0.png) 也可考慮學長資料 ![image](https://hackmd.io/_uploads/B15PoNKxC.png) 儲存指令```:wq``` ``` mount -a #重新掛載在/etc/fstab文件中定義的文件系統 ``` C.有個光碟映像檔 /mycdrom.iso 的檔案,請將他掛載到 /mydata/cdrom 裡面,而且每次開機都能自動掛載上來。 (請自行查詢光碟檔案掛載時所需要的檔案系統類型) ``` mkdir /mydata/cdrom #創建一個新的目錄 vim /etc/fstab #編輯自動掛載分區文件 /mycdrom.iso /mydata/cdrom iso9660 defaults 0 0 #加入掛載分區文件 mount -t iso9660 -o /mycdrom.iso /mydata/cdrom #一次性 添加 ISO 映像的掛載 #手動掛載一個 ISO 映像 #iso9660 是標準的 CD-ROM 文件系統格式 mount -a #重新掛載在/etc/fstab文件中定義的文件系統 ``` ![image](https://hackmd.io/_uploads/BydkkWqeA.png) D.建立一個名為 /mydata.img 的 200MB 大檔案,這個檔案格式化為 xfs ,且開機會主動的掛載於 /mydata/xfs2/ 目錄中 ``` mkdir /mydata/xfs2 #創建一個新的目錄 dd if=/dev/zero of=/mydata.img bs=1M count=200 #創建一個大小為 200MB 的空白映像文件 mkfs.xfs /mydata.img #mydata.img格式化為XFS y #確定分割磁區 vim /etc/fstab /mydata.img /mydata/xfs2 xfs defaults 0 0 #添加 mount -a #重新掛載在/etc/fstab文件中定義的文件系統 ``` # 4.基礎帳號管理,請依據底下的說明,建立或恢復許多帳號: A.請刪除系統中的 baduser 這個帳號,同時將這個帳號的家目錄與郵件檔案同步刪除。 ``` userdel -r baduser #在 Linux 系統中用於刪除一個用戶帳號,並且通過 -r 選項來移除用戶的家目錄及郵件暗房等與用戶相關的檔案 ``` /// B.有個帳號 gooduser 不小心被管理員刪除了,但是這個帳號的家目錄與相關郵件都還存在。請參考這個帳號可能的家目錄所保留的 UID 與 GID, 並嘗試以該帳號原有的 UID/GID 資訊來重建該帳號。而這個帳號的密碼請給予 MyPassWord 的樣式 ``` ll /home #查詢他的uid useradd -u 1100 gooduser # 用於創建一個新的用戶帳戶,-u 1100: 指定新用戶的用戶 ID (UID) 為 1100。gooduser: 這是新用戶的用戶名。 echo MyPassWord | passwd --stdin gooduser #設置用戶密碼 id gooduser #確認他有還原 ``` C.群組名稱為: mygroup, nogroup B.帳號名稱為: myuser1, myuser2, myuser3 通通加入 mygroup,且密碼為 MyPassWord E.帳號名稱為: nouser1, nouser2, nouser3 通通加入 nogroup,且密碼為 MyPassWord ``` groupadd mygroup groupadd nogroup useradd -G mygroup myuser1 && echo MyPassWord | passwd --stdin myuser1 useradd -G mygroup myuser2 && echo MyPassWord | passwd --stdin myuser2 useradd -G mygroup myuser3 && echo MyPassWord | passwd --stdin myuser3 useradd -G nogroup nouser1 && echo MyPassWord | passwd --stdin nouser1 useradd -G nogroup nouser2 && echo MyPassWord | passwd --stdin nouser2 useradd -G nogroup nouser3 && echo MyPassWord | passwd --stdin nouser3 ``` F.新建帳號名稱為: ftpuser1, ftpuser2, ftpuser3,無須加入次要群組,密碼為 MyPassWord,且這三個帳號主要用來作為 FTP 傳輸用的帳號, 因此需要不能互動的 shell。 ``` useradd ftpuser1 && echo MyPassWord | passwd --stdin ftpuser1 useradd ftpuser2 && echo MyPassWord | passwd --stdin ftpuser2 useradd ftpuser3 && echo MyPassWord | passwd --stdin ftpuser3 usermod -s /sbin/nologin ftpuser1 usermod -s /sbin/nologin ftpuser2 usermod -s /sbin/nologin ftpuser3 ``` # 5.管理群組共用資料的權限設計: A.建立一個名為 /srv/myproject 的目錄,這個目錄可以讓 mygroup 群組內的使用者完整使用,且【新建的檔案擁有群組】為 mygroup 。不過其他人不能有任何權限 ``` mkdir /srv/myproject chgrp mygroup /srv/myproject chmod 2770 /srv/myproject ``` B.增加 histroy 的輸出,讓 root 自己最大可達 10000 筆紀錄,且 (1)其他用戶保留預設值 (2)紀錄檔內也要紀錄 10000 筆。 ``` cp -r /bin/ls /usr/local/bin/myls chgrp mygroup /usr/local/bin/myls chmod g+s /usr/local/bin/myls ``` C.建立一個名為 /srv/change.txt 的空檔案,這個檔案的擁有者為 myuser1,擁有群組為 nogroup,myuser1 可讀可寫, nouser1 可讀,其他人無權限。 這個檔案所有人都不能執行。此外,這個檔案的最後修改時間請調整成 2020 年 02 月 5 日的 13 點 0 分 ``` touch /srv/change.txt chown myuser1 /srv/change.txt chgrp nogroup /srv/change.txt chmod 640 /srv/change.txt touch -t 202002051300 /srv/change.txt ``` # 6.檔案的搜尋與管理: A.將 /usr/sbin 與 /usr/bin 裡面,只要是具有 SUID 與/或 SGID 的權限檔案,就將該檔案連同權限,全部複製到 /root/findperm 目錄中。 ``` #以下代碼目前辨識有誤 mkdir findperm cp -a $(find /usr/sbin /usr/bin -perm /6000 2> /dev/null) /root/finperm ``` GPT ``` mkdir -p /root/findperm find /usr/sbin /usr/bin -type f -perm /6000 -exec cp -a {} /root/findperm/ \; 2> /dev/null ``` B.找出系統中檔案擁有者為 examuserya 的檔名,並將這些找到的檔名(含權限)複製到 /root/finduser/ 目錄內 ``` mkdir finduser cp -a $(find / -user examuserya 2>/dev/null) finduser ``` //C.有個名為 /srv/mylink.txt 檔案,這個檔案似乎有許多的實體連結檔。請將這個檔案的所有實體連結檔的檔名,通通複製到 /root/findlink 目錄下。 ``` mkdir findlink ls -li /srv/mylink.txt cp -a $(find / -inum 17427652 2>/dev/null) findlink ``` GPT ``` sudo mkdir -p /root/findlink ls -li /srv/mylink.txt sudo find / -inum 17427652 2>/dev/null sudo cp -a $(sudo find / -inum 17427652 2>/dev/null) /root/findlink/ ``` ``` # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH="/bin:${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/root/bin:/root/scripts:/opt/sys/bin" showip='ip addr show | grep 'inet ' ' [root@station3-221 ~]# source ~/.bash_profile bash: HISTSIZE: command not found... bash: HISTFILESIZE: command not found... -bash: alias: syserr: not found -bash: alias: =: not found -bash: alias: echo "System error message": not found bash: : command not found... ``` ``` showip='ip addr show | grep 'inet ' ' showip="ip addr show | grep 'inet '" (3%)寫一隻『大家都能執行的腳本程式』,執行名稱為:『 showip 』,執行該指令,其實輸出為資料是:『 ip addr show | grep 'inet ' 』。 請注意: (1)這隻程式定義為『本機全部用戶都能執行』,所以應該與 bin 有關,不是 sbin! (2)使用者在任何工作目錄,只要在提示字元輸入 showip 即可獲得『ip addr show | grep 'inet '』的輸出結果。 ``` ``` sudo nano /usr/local/bin/showip #!/bin/bash ip addr show | grep 'inet ' sudo chmod +x /usr/local/bin/showip showip 找出 gooduser 的第 10 個歷史命令,將找到的資料儲存到 /root/myres/ans2.txt 內 (只有一行) sudo mkdir -p /root/myres/ sudo sed -n '10p' /home/gooduser/.bash_history > /root/myres/ans2.txt ```

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