Files
dsh_shenxian/scripts/switch-B1-key.sh
T
admin 5ec99ce227
build / build-and-scan (push) Canceled after 0s
chore: 文档库全量重新入库(2026-10-20)
2026-10-20 15:05:55 +08:00

24 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
. "$(cd "$(dirname "$0")/.." && pwd)/config/load.sh"
# B1 步(在 47 上跑):uid 保真校验 + 建 47→106 专用密钥并打印公钥
set -uo pipefail
KEY=/root/.ssh/dshworker_ed25519
echo "=== 1) uid 保真校验(PG 与 SQLite 必须一致 —— 否则 106 上文件属主全错) ==="
echo -n " PG : "; PGPASSWORD=dshs_cluster_2026 /usr/bin/psql -h 127.0.0.1 -p 15432 -U dshs -d dshs -tAc \
"select string_agg(username||'='||coalesce(uid::text,'NULL'), ' ' order by row_id) from users" 2>&1 | head -1
echo -n " SQLite : "; node -e 'const D=require("better-sqlite3");const db=new D("'"$DSHS_DATA_ROOT"'/dshs.db",{readonly:true});console.log(db.prepare("select username, uid from users order by rowid").all().map(u=>u.username+"="+u.uid).join(" "))'
echo " --- 磁盘目录属主(与 uid 对照;多出的 5 个是已删用户孤儿目录) ---"
for d in "$DSHS_DATA_ROOT"/users/*/; do printf " %-38s uid=%s\n" "$(basename "$d")" "$(stat -c %u "$d")"; done
echo "=== 2) 建 47→106 专用密钥(仅用于 rsync) ==="
[ -f "$KEY" ] || ssh-keygen -t ed25519 -N "" -C "dshs-rsync-47to106" -f "$KEY" >/dev/null 2>&1
echo " PUBKEY=$(cat "$KEY.pub")"
echo "=== 3) 试连通 106:22 ==="
if ssh -i "$KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=8 root@"$DSH_PEER_PUBLIC_IP" 'echo ok' 2>/dev/null | grep -q ok; then
echo " ✓ 已可连通(公钥已装)"
else
echo " ⏳ 尚不可连通 —— 需先把我本机把这个公钥装到 106"
fi