22 lines
1.4 KiB
Bash
22 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
||||
|
|
# 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("/var/lib/dshs/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 /var/lib/dshs/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 [email protected] 'echo ok' 2>/dev/null | grep -q ok; then
|
|||
|
|
echo " ✓ 已可连通(公钥已装)"
|
|||
|
|
else
|
|||
|
|
echo " ⏳ 尚不可连通 —— 需先把我本机把这个公钥装到 106"
|
|||
|
|
fi
|