Not Exist
    • 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
# SSH Server by 資工三 111110517 范揚玄 ## 指令 安裝 ssh 伺服器 ```vim= sudo apt install openssh-server ``` 套件查詢 ```vim= dpkg -l | grep ssh ``` ssh 伺服器狀態查詢/控制 ```vim= systemctl status ssh start stop restart reload enable disable ``` 上個指令是否成功 ```vim= echo $? ``` 生成 ssh 密鑰 ```vim= ssh-keygen ssh-copy-id wrr606@UB2 ``` 產生名為 file 檔案 ```vim= touch file touch a{00..99}.cpp ``` 傳送 file 檔案 / 下載 file 檔案 ```vim= scp file wrr606@UB2: scp wrr606@UB2:file . ``` ## 使用主機名代替 IP 加上下行 ```vim= vim /etc/hosts ``` ```vim= 192.168.242.131 R2 ``` ## 0.0.0.0 在伺服端/雲端表示 **任意介面** (「監聽所有可用的介面」或「接受任意 IP 連接」) 在 PC 上表示 **尚未取得 IP** # NFS Server ## 步驟 **UB1:Server UB2:client** UB1:安裝 Server 端 ```vim= apt install -y nfs-kernel-server ``` UB1:新增要共享的資料夾 ```vim= mkdir /mynfs ``` UB1:調整資料夾權限 ```vim= chown -R nobody:nogroup /mynfs ``` UB1:加入下行 ```vim= vim /etc/exports ``` ```vim= /mynfs *(rw,sync,no_subtree_check,all_squash) ``` UB1:重啟 nfs-kernel-server ```vim= systemctl restart nfs-kernel-server ``` UB2:安裝 client 端 ```vim= apt install nfs-common -y ``` UB2:新增要共享的資料夾 ```vim= mkdir /mydata ``` UB2:關聯到 UB1 的資料夾 ```vim= mount -t nfs -o rw,resvport 192.168.242.130:/mynfs /mydata ``` 若要取消關聯 ```vim= umount /mydata ``` # 插入新硬碟 參考教學:https://reurl.cc/xv20Ve ## VMWare 操作 ### 插入 USB 關機狀態下,調整成 USB 3.1 後再插入 USB ### 新增虛擬硬碟 ![image](https://hackmd.io/_uploads/SJdSMrBr1l.png) 選擇 Add 新增硬體,並選擇 Hard Disk ## 步驟 查看掛載點 ```vim= lsblk ``` 查看磁碟使用情況 ```vim= df -h ``` 查看插入的所有硬碟 ```vim= ls /dev/sd* ``` 分割磁碟 ```vim= fdisk /dev/sdb 輸入 n 按 Enter 輸入 p 按 Enter 輸入 1 按 Enter 按 Enter 輸入 w 再按 Enter ``` 用 fdisk 確認分割區 ```vim= fdisk -l /dev/sdb ``` 格式化磁碟 ```vim= mkfs -t ext4 /dev/sdb1 ``` 掛載硬碟 ```vim= mount /dev/sdb1 /mydisk ``` ## 開機自動掛載 查詢硬碟 UUID ```vim= blkid ``` 將 UUID 複製貼上 ```vim= vim /etc/fstab ``` ```vim= UUID=fa7f7fe7-e7ac-4b16-8352-0713428eda08 /mydisk ext4 defaults 0 1 ``` 重開機後確認是否成功掛載 ```vim= df -h ``` # MySQL 參考教學:https://blog.tarswork.com/post/mariadb-install-record ## 步驟 ### Server 端 安裝金鑰 ```vim= sudo apt-get install apt-transport-https curl sudo mkdir -p /etc/apt/keyrings sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp' ``` 加入儲存庫 ```vim= vim /etc/apt/sources.list.d/mariadb.sources ``` ```vim # MariaDB 11.1 repository list - created 2023-11-08 06:16 UTC # https://mariadb.org/download/ X-Repolib-Name: MariaDB Types: deb # deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # URIs: https://deb.mariadb.org/11.1/ubuntu URIs: https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.1/ubuntu Suites: jammy Components: main main/debug Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp ``` 安裝 MariaDB ```vim= apt-get update apt install mariadb-server systemctl status mariadb mysql_secure_installation ``` 編輯 MariaDB 設定檔 ```vim= vim /etc/mysql/mariadb.conf.d/50-server.cnf ``` ```vim= bind-address = 0.0.0.0 ``` 新增資料庫權限 ```vim= mysql -u root -p GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'user' WITH GRANT OPTION; FLUSH PRIVILEGES; ``` 關閉防火牆並重開 ```vim= systemctl stop ufw systemctl disable ufw service mysql restart ``` ### Client 端 安裝客戶端 ```vim= apt install mysql-client ``` 遠端連入資料庫 ```vim= mysql -h 192.168.242.130 -u root -p ``` ## 指令 查看資料庫 ```vim= show databases; ``` 創建資料庫 ```vim= create database testdb; ``` 使用資料庫 ```vim= use testdb; ``` 創建資料表 ```vim= create table addrbook(name varchar(50) not null, phone char(10)); ``` 插入資料 ```SQL= INSERT INTO addrbook(name, phone) VALUES ("tom", "0912123456"); INSERT INTO addrbook(name, phone) VALUES ("mary", "0912123567"); ``` 使用 SQL 語法查詢資料 ```SQL= SELECT name,phone FROM addrbook; ``` 查看 CPU 使用率 ```vim= apt install dstat dstat -c -n -d 10 ``` 監控系統 ```vim= top -------------------------- apt install iotop iotop ``` # Apache 參考教學:https://docs.ossii.com.tw/books/ubuntu-server-2004-apache-mariadb-php ## 步驟 安裝 apache ```vim= apt -y install apache2 apache2-utils ``` 確認啟用情況 ```vim= systemctl status apache2 ``` ![image](https://hackmd.io/_uploads/rJqUpdSHye.png) 安裝 PHP ```vim= apt install software-properties-common add-apt-repository ppa:ondrej/php apt update -y apt install php8.1 libapache2-mod-php8.1 php8.1-gd php8.1-mysql php8.1-curl php8.1-mbstring php8.1-intl -y apt install php8.1-gmp php8.1-bcmath php8.1-imagick php8.1-xml php8.1-zip -y a2enmod php8.1 systemctl restart apache2 ``` 測試 PHP 版本資訊 ```vim= vim /var/www/html/info.php ``` ```php= <?php phpinfo(); ?> ``` ![image](https://hackmd.io/_uploads/SJyr6_HH1g.png) 連線去資料庫提取資料 ```vim= vim /var/www/html/test.php ``` ```php= <?php $servername="127.0.0.1"; $username="root"; $password="user"; $dbname="testdb"; $conn = new mysqli($servername, $username, $password, $dbname); if($conn->connect_error){ die("connection failed: " . $conn->connect_error); } else{ echo "connect OK!" . "<br>"; } $sql="select name,phone from addrbook"; $result=$conn->query($sql); if($result->num_rows>0){ while($row=$result->fetch_assoc()){ echo "name: " . $row["name"] . "\tphone: " . $row["phone"] . "<br>"; } } else { echo "0 record"; } ?> ``` ![image](https://hackmd.io/_uploads/B1R7TOHHJx.png) # Apache 網頁啟用密碼驗證 參考教學:https://xenby.com/b/104-%E6%95%99%E5%AD%B8%E5%B0%8D%E7%B6%B2%E9%A0%81%E5%95%9F%E7%94%A8%E5%AF%86%E7%A2%BC%E9%A9%97%E8%AD%89-apache ## 步驟 安裝 apache2-utils ```vim= apt-get install apache2-utils ``` 新增使用者 ```vim= sudo htpasswd -c /etc/apache2/.htpasswd username001 ``` 使用 vim 修改設定檔 ```vim= vim /etc/apache2/sites-enabled/000-default.conf ``` ```html= <Directory "/var/www/html"> AuthType Basic AuthName "You need to login" AuthUserFile /etc/apache2/.htpasswd Require valid-user </Directory> ``` 重啟伺服器 ```vim= systemctl restart apache2 ``` ![image](https://hackmd.io/_uploads/rJ9uTurHJe.png) # Python Flask ## 步驟 安裝 python ```vim= apt install python3-pip -y ``` 安裝 Flask ```vim= pip3 install flask ``` 執行 `run.py` ```python= # run.py from flask import Flask app = Flask("test") @app.route('/') def hello_world(): return '<h2>Hello, World!</h2>' @app.route('/test') def hello_world2(): return '<h2>Test</h2>' if __name__ == '__main__': app.run(host='0.0.0.0', port=3000, debug=True) ``` ```vim= python3 run.py ``` # 使用者管理 ## 指令 新增使用者 ```vim= useradd -m Function -s /bin/bash ``` 更改使用者密碼 ```vim= passwd Function ``` 刪除使用者及其目錄 ```vim= userdel -r Function ``` 新增部門 ```vim= groupadd teacher groupadd english ``` 新增成員並加入部門(-g 主要部門 -G 次要部門) ```vim= useradd -g teacher -G english Sam ``` 顯示使用者訊息 ```vim= id Sam ``` 新增成員並加入賦予 sudo 權限 ```vim= useradd -G sudo Sam ``` 切換使用者 ```vim= su Sam ``` # Shell 腳本 創建 Shell 腳本 ```vim= vim test.sh ``` ```vim= #!/user/bin/bash touch {1..3} ``` 使用 Bash 執行 ```vim= bash a.sh ``` # 硬連結(Hard Link) 與 符號連結(Symbolic Link) ## 硬連結(Hard Link) - **類似 C++ 的 Reference。** - 無論修改哪一個,另一個也會同步變化。 - 刪除原始檔案,硬連結仍然可以正常訪問檔案數據。 - 硬連結不能跨越不同的文件系統(例如,不能在 `/home` 和 `掛載硬碟` 之間創建硬連結)。 - 不能指向資料夾。 ### 範例 ```vim= ln test.txt test_hardlink.txt ``` ## 符號連結(Symbolic Link) - **類似 Windows 的捷徑。** - 符號連結指向檔案的路徑。 - 如果原始檔案被刪除,符號連結會變成「斷開的連結」或「死連結」,無法再正常訪問。 - 符號連結可以跨越不同的文件系統,也可以指向資料夾。 ### 範例 ```vim= ln -s test.txt test_symboliclink.txt ``` # 單引號 `'` 和 雙引號 `"` ## 單引號 `'` - 所見及所得 - 特殊字符不會生效 ## 雙引號 `"` - 可印出指令 - 雙引號內的內容會進行變數替換和特殊字符解釋 # 監控使用者 查看使用者 ```vim= w ``` pts: 使用 ssh 連線登入 tty: 使用虛擬終端登入 記憶體使用率 ```vim= free -h ``` ```vim= last ``` # 更改 host 名稱 更改 host 為 UB1 ```vim= hostnamectl set-hostname UB1 ``` # SAMBA 分享 安裝 SAMBA 伺服器 ```vim= apt install samba samba-common -y ``` 新增資料夾 ```vim= mkdir sharea shareb ``` 調整權限為 777 ```vim= chmod 777 a b ``` 新增測試用的帳號 ```vim= adduser Sam adduser Tom ``` 設定密碼 ```vim= smbpasswd -a Sam smbpasswd -a Tom ``` 修改配置檔,新增下列文字(**路徑是絕對位置,不是相對位置**) ```vim= vim /etc/samba/smb.conf ``` ```vim= [sharea] path = /home/user/sharea comment = guest access folder writable = yes browseable = yes guest ok = yes [shareb] path = /home/user/shareb comment = have auth can access writable = yes browseable = yes valid users=Sam,Tom write list=Sam,Tom ``` 重啟 Samba 伺服器 ```vim= systemctl restart smbd ``` Windows 檔案總管輸入 `\\192.168.242.130`(R1 IP) ![image](https://hackmd.io/_uploads/ByD7VOSLye.png) # 將虛擬機設定為路由 以 R1 當作路由 ![未命名](https://hackmd.io/_uploads/HkstlFrLyx.png) ## VMWare 設定 R1: `NAT、LAN Segment(LAN10)、LAN Segment(LAN20)` H1: `LAN Segment(LAN10)` H2: `LAN Segment(LAN20)` ## CMD 部分 H1: `192.168.10.1` :::info ```vim= ip addr add 192.168.10.1/24 dev ens33 ifconfig ens33 0 ip route add default via 192.168.10.254 ``` ::: H2: `192.168.20.1` :::info ```vim= ip addr add 192.168.20.1/24 dev ens33 ifconfig ens33 0 ip route add default via 192.168.20.254 ``` ::: R1: `192.168.10.254` `192.168.20.254` :::info ```vim= ip addr add 192.168.10.254/24 dev ens37 ip addr add 192.168.20.254/24 dev ens38 ifconfig ens37 0 ifconfig ens38 0 ``` ```vim= echo 1 > /proc/sys/net/ipv4/ip_forward ``` ::: 相互 ping 的通就是成功了 # DHCP Server 以 R1 當作路由 ![未命名](https://hackmd.io/_uploads/HkstlFrLyx.png) ## 步驟 以上文 `「將虛擬機設定為路由」` 接續 參考教學:https://www.kjnotes.com/linux/118 R1: :::info 安裝 DHCP 套件 ```vim= apt install isc-dhcp-server -y ``` 在配置檔加入下列文字: ```vim= vim /etc/dhcp/dhcpd.conf ``` ```vim= subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.1 192.168.10.100; option subnet-mask 255.255.255.0; option routers 192.168.10.254; option broadcast-address 192.168.10.255; default-lease-time 600; max-lease-time 7200; } subnet 192.168.20.0 netmask 255.255.255.0 { range 192.168.20.1 192.168.20.100; option subnet-mask 255.255.255.0; option routers 192.168.20.254; option broadcast-address 192.168.20.255; default-lease-time 600; max-lease-time 7200; } ``` 重啟套件 ```vim= systemctl restart isc-dhcp-server ``` ::: # NAT 網路 網路分布: ![未命名](https://hackmd.io/_uploads/H1zEKE3Qkg.png) 以上文 `「DHCP Server」` 接續 網卡: R1: `NAT、LAN Segment(LAN10)、LAN Segment(LANR1R2)` R2: `NAT、LAN Segment(LAN20)、LAN Segment(LANR1R2)` H1: `LAN Segment(LAN10)` H2: `LAN Segment(LAN20)` ## 步驟 1. 在 Ubuntu 中設定每個節點的每個網卡 IP 至上圖位置 2. R1、R2 都需按照上文 `「DHCP Server」` 安裝 DHCP 套件並開啟路由功能 :::info ```vim= echo 1 > /proc/sys/net/ipv4/ip_forward ``` ::: 3. R1: :::info 在配置檔加入下列文字: ```vim= vim /etc/dhcp/dhcpd.conf ``` ```vim= subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.1 192.168.10.100; option subnet-mask 255.255.255.0; option routers 192.168.10.254; option broadcast-address 192.168.10.255; default-lease-time 600; max-lease-time 7200; } ``` 重啟套件 ```vim= systemctl restart isc-dhcp-server ``` 配置 `12.1.1.1` ```vim= ip addr add 12.1.1.1/24 dev ens38 ``` 設定轉發 ```vim= ip route add 192.168.20.0/24 via 12.1.1.2 ``` ::: 4. R2: :::info 在配置檔加入下列文字: ```vim= vim /etc/dhcp/dhcpd.conf ``` ```vim= subnet 192.168.20.0 netmask 255.255.255.0 { range 192.168.20.1 192.168.20.100; option subnet-mask 255.255.255.0; option routers 192.168.20.254; option broadcast-address 192.168.20.255; default-lease-time 600; max-lease-time 7200; } ``` 重啟套件 ```vim= systemctl restart isc-dhcp-server ``` 配置 `12.1.1.2` ```vim= ip addr add 12.1.1.2/24 dev ens38 ``` 設定轉發 ```vim= ip route add 192.168.10.0/24 via 12.1.1.1 ``` ::: 使用 ping 測試 H1 是否可以 ping 到 H2

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