bug: SSH 认证失败提示是模板文案,与真实原因无关(误导用户去 ssh-add)
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 395
- Avg merge
- 21h 48m
- Merged PRs (30d)
- 776
Description
## 现象
SSH 主机认证失败时,`ssh_exec` 和 UI 连接错误都返回同一句话:
> SSH agent has no key the remote accepts from the configured identity set. Load the matching private key with `ssh-add`, then try again.
这句话在本次排障中**完全是错的**,直接把人带偏了约一小时:
- 私钥**已经**加载在 ssh-agent 里(`ssh-add -l` 能看到对应指纹)
- 公钥**已经**装在远端 `~/.ssh/authorized_keys` 里
- 远端 sshd 允许 root 公钥登录(`PermitRootLogin yes`、默认 `AuthorizedKeysFile`、`PubkeyAuthentication` 未关闭)
- 真实原因是**缓存的 identity 不对**:主机通过「设置 → 远程连接」添加时,写入的 `IdentityFile` 是 `~/.ssh/id_ed25519_github`(选错了),而服务器上装的是 `id_rsa_aliyun_ecs` 对应的公钥
真实错误只出现在 app 日志里,UI 和工具返回都没有带出来:
```
~/Library/Application Support/Cindy/logs/main-.log
[WARN] [remote-ssh/ipc] ssh connect failed {
id: 'aliyun-qd',
error: 'All configured authentication methods failed'
}
```
## 原因(反查 app bundle)
`authFailureHint()` 是按认证**形态**挑文案,而不是按真实失败原因:
```js
return r.authMethod === "agent"
? (!!r.identityFile || (r.sshAuthentication?.allowedAgentFingerprints?.length ?? 0) > 0
? "SSH agent has no key the remote accepts from the configured identity set. Load the matching private key with `ssh-add`, then try again."
: "SSH agent has no key the remote accepts. Run `ssh-copy-id ...`")
: ...
```
只要 `authMethod === "agent"` 且配了 `identityFile`,就一律输出「去 ssh-add」——不管钥匙是否已经在 agent 里、是否已经装在服务器上,也不管这次失败是否与 agent 有关。
## 建议
把真正能区分问题的信息带进错误里:
1. 本次实际使用的 **IdentityFile**(以及它是否成功解析出指纹)
2. 实际提供给服务器的 **key fingerprint**
3. 底层原始错误(`All configured authentication methods failed`,日志里已有)
哪怕只带第 1 条,这次也能五分钟解决:提示里出现 `IdentityFile: ~/.ssh/id_ed25519_github` 就直接指向问题了。
## 环境
- Cindy 0.1.76 / macOS
- 主机通过「设置 → 远程连接」添加,认证方式 agent(`# xdt-maker:auth=agent`),`IdentitiesOnly yes`
Contributor guide
Research direction
Start by locating authFailureHint() and the ssh_exec and UI connection-error callers, then inspect the logged failure at ~/Library/Application Support/Cindy/logs/main-.log. Check how IdentityFile, its resolved fingerprint, and the underlying authentication error are available. Done means the returned error identifies the configured identity and preserves the relevant original failure instead of always directing users to ssh-add.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100