1月 04, 2024

常用 git 指令與自建 Gitea Server

在 Windows 環境下
  • git 個人設定值存放於 C:\Users\account\.gitconfig
  • ssh 個人公私錀存放於 C:\Users\account\.ssh\
如果要產生公私錀,可以透過 PowerShell 執行 ssh-keygen

初始資訊設定(作者名與郵件)與查看設定值:
git config --global user.name "Foo Bar"
git config --global user.email foo@bar.com

git config --global --list
git config --global --list --show-origin
git 上傳方式有 HTTPS 與 SSH 兩種:

1. 透過 HTTPS 傳輸相對簡單,直接將帳號密碼附在 URL 內即可,但因有密碼外露問題,所以 GitHub 採用 Personal access tokens 作為取代;這是一個短天期的通關碼(token),讓共同參與成員可以對源碼庫進行操作,首次上傳會出現提示要求輸入通關碼
2. 使用 SSH 應當是較為安全的管道,在原始碼上傳前,需預先部署公鑰在遠端伺服器(GitHub或Gitea),本地端推送(PULL)時則出示私鑰進行授權。所以記得使用 ssh-keygen 產生公私鑰放在家目錄 [.ssh] 資料夾。

[HTTPS]
git init
git checkout -b main                                   // 建立並切換到 main 分支
git add .                                              // 加入檔案到 staging
git commit -m "first commit"                           // 加到本地 repository
git remote add origin https://example.com/user/foo.git // git remote add [remote-name] [remote-url]
git push -u origin main                                // 推送本地分支(main)到遠端位址(origin)
[SSH]
git init
git checkout -b main
git add README.md
git commit -m "first commit"
git remote add origin user@example.com:user/foo.git    // 透過 SSH 上傳需佈建公鑰(id_rsa.pub)在遠端
git push -u origin main
[其他常用指令]
git log            // 列出提交歷史
git status         // 列出狀態
git remote -v      // 列出遠端位址

1月 03, 2024

在 Oracle Cloud 上安裝 Alpine Linux

1. 建立一個以 Ubuntu 為作業系統的虛擬機(當作空殼)

2. 到 Alpine Linux 官網下載 VIRTUAL 版本的映像檔。例如 alpine-virt-3.19.0-x86_64.iso

3. 刷入映像檔

# sudo dd if=alpine-virt-3.19.0-x86_64.iso of=/dev/sda

4. 重新開機

5. 使用 Oracle Cloud 主控台連線(console)操作,進行安裝前準備

# mkdir /media/setup
# cp -a /media/sda/* /media/setup
# mkdir /lib/setup
# cp -a /.modloop/* /lib/setup
# /etc/init.d/modloop stop
# umount /dev/sda
# mv /media/setup/* /media/sda/
# mv /lib/setup/* /.modloop/
6. 循原本方式進行系統安裝(setup-alpine),網路介面直接用 eth0(dhcp)。安裝後驚人的空間使用(僅150MB)

1月 01, 2024

在 Oracle Cloud 建立首個虛擬主機

Oracle Cloud 資安要求嚴謹,首次註冊即強制要求啟動雙因子驗證。每次登入除了帳號密碼外,皆需搭配特定手機軟體(Oracle Mobile Authenticator)方能進入主控台。

主控台最基礎操作就從建立虛擬機(VM compute instance)開始,節點會以用戶的家鄉區(Home Region)作為預設值。基本上 Always Free 方案能選的項目不多,處理器部份固定是 E2.micro 然後作業系統有 Oracle Linux,Ubuntu, CentOS 等。

12月 31, 2023

在 Debian 下使用 libusb 開發程式

apt-get install gcc usbutils libusb-1.0-0-dev

12月 27, 2023

Oracle 雲端免費資源(Cloud Always Free)

Oracle Cloud 相較於 Google Cloud Platform(GCP) 除了同樣提供免費運算資源外,機房區域多了東京可以選擇,對於亞太區傳輸延遲顯得更有優勢。另外 Oracle Cloud 登入強制啟用 2FA(Oracle Mobile Authenticator) 認證!

The Home Region(家鄉區)
When you sign up for Oracle Cloud Infrastructure, Oracle creates a tenancy for you in one region. This is your home region. Your home region is where your IAM resources are defined. Your home region contains your account information and identity resources.It is not changeable after your tenancy is provisioned. (區域列表)
Always Free Resources
All Oracle Cloud Infrastructure accounts (whether free or paid) have a set of resources that are free of charge in the home region of the tenancy, for the life of the account. These resources display the Always Free label in the Console (for Ampere A1 Compute shapes, see Compute). (圖例)
Compute(免費運算節點只能在家鄉區建立!)
All tenancies get a set of Always Free resources in the Compute service for creating compute virtual machine (VM) instances. You must create the Always Free compute instances in your home region.
  • Micro instances (AMD processor): All tenancies get up to two Always Free VM instances using the VM.Standard.E2.1.Micro shape, which has an AMD processor.(節點規格, 流量計價)
  • Ampere A1 Compute instances (Arm processor): All tenancies get the first 3,000 OCPU hours and 18,000 GB hours per month for free for VM instances using the VM.Standard.A1.Flex shape, which has an Arm processor.
Idle Compute Instances(閒置的節點會被收回)
Idle Always Free compute instances may be reclaimed by Oracle. Oracle will deem virtual machine and bare metal compute instances as idle if, during a 7-day period, the following are true:
  • CPU utilization for the 95th percentile is less than 20%
  • Network utilization is less than 20%
  • Memory utilization is less than 20% (applies to A1 shapes only)

12月 19, 2023

在 Virtualbox 跑 Fortigate VM

 1. 先到 Fortinet Download/VM Images (需登入)

2. 防火牆(FortiGate)原廠未提供 Vbox 格式,在此選 FGT KVM 然後手動轉檔,像是:

  • FGT_VM64_KVM-v6.M-build2093-FORTINET.out.kvm.zip
  • FGT_VM64_KVM-v7.4.0.F-build2360-FORTINET.out.kvm.zip
3. 透過 qemu 工具轉檔成 .vdi 格式
  • qemu-img.exe convert -O vdi fortios.qcow2 fortios.vdi
4. 在 VirtualBox 開一台新機器(Linux 64bit)掛載 vdi 成功進入基礎環境,功能待測。

※如果是要跑 FortiWeb(WAF) 可以省去轉檔過程,網站直接有提供 VirtualBox 格式映像檔。

12月 13, 2023

組7K家用文書機:Celeron G6900 華碩 PRIME H610M-K D4-CSM

原先擺在家裡的電腦用很久(2016/06),最近主機板偵測不到 SATA 或無法開機索性整台換了。看一下故障週期,好像6年是個大關,雖然CPU、硬碟還有電源供應器都是好的。

這年頭組台電腦不容易,零件變的很貴。低階CPU缺料沒有Pentium款;然後入門款 Core i3 把處理器跟顯示晶片拆開來賣,在AMD陣營這邊也是一樣!最後退一萬步...條件篩完只剩Celeron能選!

Total = $7889 | 硬體參數

. .

12月 01, 2023

輕量經 Windows 11 作業系統

 輕量級的 Windows 11 作業系統,由 NTDEV 製作

  • tiny11:最新版基於Windows 11 23H2,可以安裝中文語言包,映像檔大小3.5G。
  • tiny11 core:映象檔縮小到 2GB,刪除 WinSxS、Edge等功能;不建議用於正式環境,安全性無法更新。

11月 02, 2023

USB 資料對傳線(USB Host to Host Data Transfer)

Prolific PL27A1 Super-Speed USB Host to Host Data Transfer Controller

The PL27A1 is a single-chip SuperSpeed USB 3.0 Host-to-Host bridge controller specially designed for USB host to host data transfer. (通常搭公版軟體 PCLinq5 發售;可透過 libusb 程式化運作)

The PL27A1 chip offers external firmware customization for various data transfer mode protocols:
- WINUSB(Transfer cable)
- CDC/ACM (USB Serial Device)
- RNDIS (Network Cable)

PL27A1 實際產品

另一種標示為資料傳輸與鍵鼠(KM)控制的的產品 (libusb 無法正常驅動)
  • j5create JUC100 USB 2.0 資料對傳線:規格參數 - WindowsLinux
  • StarTech.com KM Switch Cable with File Transfer (SVKMS2)

9月 12, 2023

設定 BIND9 伺服器

關於 BIND 的設定之前(2014)有寫過一篇,不過年代久遠。兩相對照語法,其實架構沒太大改變。現在都用免費託管方案 Cloudflare DNS 顯少自己維運,畢竟還是有機會被打爆。

/etc/bind# vim named.conf.local

zone "example.com" in {
  type master;
  file "/etc/bind/db.example.com";
};

/etc/bind# vim db.example.com

$TTL    86400
$ORIGIN example.com.    ; base domain-name

@  IN  SOA  dns.example.com. admin.example.com. (
   20230909    ; Serial
   43200       ; Refresh
   3600        ; Retry
   1209600     ; Expire
   180 )       ; Minimum TTL

; Nameservers
@                  IN  NS  dns.example.com.;

; Records
dns.example.com.   IN  A   [IP];
test.example.com.  IN  A   [IP];

/etc/bind# vim named.conf.options

options {
  directory "/var/cache/bind";
  dnssec-validation auto;
  
  auth-nxdomain yes;    # conform to RFC1035
  listen-on-v6 { none; };
  listen-on port 53 { any; };
  allow-query { any; };
  allow-query-cache { none; };
  recursion no; 
  also-notify { };
};