mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 17:10:43 +00:00
诊断结论:EzHub 的 SSH 服务是**系统 OpenSSH 9.6**(banner 看出来的),
不是 Gitea/Forgejo 内置的 SSH 服务。
密钥在 EzHub 上注册的指纹和本机完全一致
(SHA256:Acmu49YQcjw3m5WefOXSBzYNY2WPHLL2vvhnlYRAttA),
但服务端一直返回 Permission denied (publickey,password)。
说明 git 用户的 authorized_keys 没有跟 Gitea 数据库同步 ——
这是服务端配置问题,客户端怎么试都过不去。
服务端要做的(任选其一):
a) 开启内置 SSH:app.ini 里 START_SSH_SERVER = true 并放行端口
b) 继续用系统 OpenSSH,但给 sshd 加 AuthorizedKeysCommand
指向 gitea/forgejo 的 keys 子命令
PS:这个实例的 UI 主题是 forgejo-auto,实际是 Forgejo。
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
r'''查 Gitea 自己报的 clone 地址,看 SSH 到底该连哪里。
|
|
|
|
现象:SSH 连得上(服务端回了 publickey,password),
|
|
但本机送出的公钥一直被拒。可能是:
|
|
* SSH 用的不是 22 端口
|
|
* 主机名不是 git.261826.xyz
|
|
* 密钥加到了别的账号
|
|
这个脚本把 Gitea 官方给出的地址拉出来对一下。
|
|
'''
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
TOKEN_FILE = Path.home() / ".ykxmz" / "ezhub_token"
|
|
TOKEN = (TOKEN_FILE.read_text(encoding="utf-8").strip()
|
|
if TOKEN_FILE.is_file() else "")
|
|
|
|
BASE = "https://git.261826.xyz/api/v1"
|
|
HEAD = {"Authorization": "token " + TOKEN, "User-Agent": "ykxmz"}
|
|
|
|
|
|
def get(path: str):
|
|
with urllib.request.urlopen(
|
|
urllib.request.Request(BASE + path, headers=HEAD),
|
|
timeout=30) as resp:
|
|
return json.loads(resp.read().decode("utf-8", "replace"))
|
|
|
|
|
|
def main() -> int:
|
|
print(" 一、仓库自己声明的 clone 地址")
|
|
repo = get("/repos/xmz/ykxmz")
|
|
for key in ("clone_url", "ssh_url", "html_url", "default_branch",
|
|
"empty", "size"):
|
|
if key in repo:
|
|
print(" %-16s %s" % (key, repo[key]))
|
|
|
|
print()
|
|
print(" 二、当前用户注册了哪些 SSH 公钥")
|
|
try:
|
|
keys = get("/user/keys")
|
|
if not keys:
|
|
print(" **一把都没有** —— 密钥没加成功")
|
|
for k in keys:
|
|
print(" id=%-4s %-14s %s" % (k.get("id"), k.get("title"),
|
|
(k.get("key") or "")[:52] + "…"))
|
|
print(" fingerprint=%s" % (k.get("fingerprint") or "?"))
|
|
except Exception as exc: # noqa: BLE001
|
|
print(" 查询失败: %s" % exc)
|
|
|
|
print()
|
|
print(" 三、对照")
|
|
print(" 本机公钥指纹: SHA256:Acmu49YQcjw3m5WefOXSBzYNY2WPHLL2vvhnlYRAttA")
|
|
print(" 本机公钥内容: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMFMh2Zqwm+8"
|
|
"KFhU3DhzhOO5Sx7cIzybYqUsrbt1c3ly")
|
|
|
|
print()
|
|
print(" 四、服务端版本与配置")
|
|
try:
|
|
ver = get("/version")
|
|
print(" Gitea: %s" % ver.get("version"))
|
|
except Exception as exc: # noqa: BLE001
|
|
print(" 取版本失败: %s" % exc)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|