
本文整理自我在 Ubuntu、GitLab、SSH 之間來回踩雷的過程,並透過 ChatGPT 一步步拆解問題與重構流程。
前一篇製作Git自動週報的文章:https://ithelp.ithome.com.tw/articles/10398571
事情一開始非常單純:
我要在自己的環境裡,每週自動整理 Git 專案的變更,產出一份 HTML 週報,給自己看也方便對團隊說明:
聽起來就是:
git fetch/git log 收集資料結果實際做下去,卡了:
ssh -T eip-git 可以,ssh -T git@10.122.99.999 卻跳 password?這篇就是把這一連串「明明看起來都對但就是怪怪的」的過程整理成一篇技術心得。
一開始我在 Windows PowerShell 裡跑:
ssh-keygen -t ed25519 -C "henry-weekly-bot"
又想把金鑰存到 Linux 的 /home/.../.ssh,結果得到:
Saving key "/home/UserA/.ssh/id_ed25519_weekly" failed: No such file or directory
後來才發現,我實際上在三個不同「世界」亂跳:
路徑、使用者、檔案系統全都不一樣,但我一開始完全把它們混在一起。
最大教訓:
先問自己:「腳本實際在哪個環境執行?」金鑰就應該生成在那裡。
最後我選擇的策略是:
承認 weekly.sh 就跑在 Ubuntu 的 root 底下,所以:
/root/.ssh/
weekly.sh 在 Ubuntu 的 root 的 shell 裡執行在 Ubuntu / root 底下,最後穩定的設定是:
mkdir -p /root/.ssh
ssh-keygen -t ed25519 -C "henry-weekly-bot" \
-f /root/.ssh/id_ed25519_weekly
chmod 700 /root/.ssh
chmod 600 /root/.ssh/id_ed25519_weekly
chmod 644 /root/.ssh/id_ed25519_weekly.pub
三個 chmod 的意義:
| 目標 | 權限 | 說明 |
|---|---|---|
/root/.ssh |
700 | SSH 要求 .ssh 只能 root 進入 |
id_ed25519_weekly |
600 | 私鑰不能被其他人讀取 |
id_ed25519_weekly.pub |
644 | 公鑰可讀但不可修改 |
ssh eip-git 可以、ssh git@10.122.99.999 卻要密碼?最重要的設定:
Host eip-git
HostName 10.122.99.999
User git
Port 22
IdentityFile /root/.ssh/id_ed25519_weekly
IdentitiesOnly yes
StrictHostKeyChecking accept-new
差異如下:
| 指令 | 結果 |
|---|---|
ssh -T eip-git |
套用上方設定 → 使用正確金鑰 |
ssh -T git@10.122.99.999 |
完全不走 Host alias → 被要求輸入密碼 |
原本:
origin http://10.122.99.999:8077/root/EIP.git
這會導致:
於是我到 GitLab 尋找 SSH URL:
git@10.122.99.999:root/EIP.git
後來設定成:
git remote set-url origin eip-git:root/EIP.git
這樣 Git 會確定使用 SSH config。
origin/main,避免週報看錯版本不依賴本地 main:
git branch -D main
git branch -r
統一設定:
LOG_SINCE="8 days ago"
LOG_UNTIL="yesterday"
TARGET_BRANCH="origin/main"
所有分析明確指定:
git log "$TARGET_BRANCH" --since="$LOG_SINCE" --until="$LOG_UNTIL"
避免「分析舊版本」。
輸出格式標準化:
===== COMMIT START =====
Commit: ...
Author: ...
Date: ...
Message: ...
TotalChangedLines: ...
[FILES]
[LARGE_DIFF_SUMMARY]
[ADDED_LINES]
[DELETED_LINES]
[SENSITIVE_CANDIDATES]
...
===== COMMIT END =====
敏感字:
password|passwd|pwd|token|secret|apikey|api_key|authorization|bearer|jwt|
connectionstring|datasource|user id=|select |insert |update |delete |
drop table|truncate
我把所有任務規格 + commit 資料放同一個 prompt。
統一要求:
/EIP_spec/weekly_reviews
YYYYMMDDHHMM_CommitCount_AuthorCount.html
結果:
| 項目 | 改造前 | 改造後 |
|---|---|---|
| Remote | HTTP | SSH |
| 執行環境 | 多重混用 | 全部鎖在 Ubuntu root |
| 分析分支 | 本地 main | origin/main |
| LLM 呼叫 | 多段 | 單一 prompt |
| 敏感檢查 | 手動 | regex + LLM |
| 稳定度 | 不穩 | 很穩 |
我在 Ubuntu 裡使用 SSH 連到 GitLab:
`ssh -T git@10.122.99.999` 會跳出要密碼,
但 `ssh -T eip-git` 又能正常顯示 Welcome。
請你當成我的 SRE,根據這兩個結果,
推論 SSH config、金鑰權限、remote URL 的可能問題,
並提供排查順序與最終推薦設定。
請幫我把 weekly.sh
改成只分析 origin/main。
流程包含:
- fetch
- 時間區間統一
- commit 取得
- authors 統計
- 產生結構化 commit 區塊
請用 bash 示範。
以下是結構化 commit 資料,使用
===== COMMIT START ===== / ===== COMMIT END =====
請輸出:
1. 本週變更總覽(3-5 行)
2. 每筆 commit 摘要(2-3 行)
3. 高風險 / 需人工確認清單(條列式)
格式需為 HTML。
我目前使用這段 regex:
password|passwd|pwd|token|secret|apikey|api_key|authorization|bearer|jwt|connectionstring|datasource|user id=|select |insert |update |delete |drop table|truncate
請協助:
- 哪些容易誤判?
- 哪些重要類型沒被覆蓋?
- 幫我重構為更清晰的分類(如:憑證 / SQL / 帳號系統)
- 給我改良版 regex。
我已完成 weekly.sh(SSH + git log + LLM 產出 HTML)。
請幫我整理成可維護的設計文件,包含:
- 需求目標
- 系統架構
- 資料流程
- 關鍵設計決策
- 未來可擴充方向