From e18c5a0815f9af9154b472389448989ced7d53b8 Mon Sep 17 00:00:00 2001 From: toom1996 <23cm.cn@gmail.com> Date: Wed, 21 Oct 2026 00:06:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Git=20Bash=20=E4=B8=8B=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=20Windows=20=E7=94=A8=E6=88=B7=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E7=A7=81=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/push-build.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/push-build.sh b/scripts/push-build.sh index 380da8b..e4cadd0 100644 --- a/scripts/push-build.sh +++ b/scripts/push-build.sh @@ -37,6 +37,22 @@ if [ -f .env ]; then set -a; . ./.env; set +a fi +# Git Bash 的 $HOME 常是 /home/,而 Windows 上生成的密钥在 C:\Users\\.ssh 下。 +# 这里自动兜底,避免在 Git Bash 里 ssh 找不到私钥而报 publickey denied。 +if [ -z "${SSH_KEY:-}" ]; then + # Windows 用户目录优先:Git Bash 的 $HOME 下可能还躺着一把无关的旧钥匙 + for cand in "/c/Users/${USERNAME:-}/.ssh/id_ed25519" "${USERPROFILE:-}/.ssh/id_ed25519" "$HOME/.ssh/id_ed25519"; do + if [ -n "$cand" ] && [ -f "$cand" ]; then + SSH_KEY="$cand" + break + fi + done +fi +if [ -n "${SSH_KEY:-}" ]; then + SSH_OPTS="$SSH_OPTS -i $SSH_KEY" + echo " 使用私钥:$SSH_KEY" +fi + TUNNEL_PID="" cleanup() { [ -n "$TUNNEL_PID" ] && kill "$TUNNEL_PID" 2>/dev/null || true; } trap cleanup EXIT