SSH — sing-box
sing-box 提供 SSH 客户端出站。标准 SSH 特性 —— 密码鉴权、带 passphrase 的密钥鉴权、主机密钥锚定、横幅覆盖 —— 都已暴露。
出站
type: "ssh":
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
user | string | (server-dependent) | <username> | SSH 登录名。 |
password | string | (unset) | <string> | 密码鉴权。可与密钥鉴权并用 —— 两者都设时 sing-box 优先尝试密码。 |
private_key | badoption.Listable[string] | [] | <PEM block> | 内联私钥。接受单个 PEM 字符串或 PEM 字符串列表。 |
private_key_path | string | (unset) | <file path> | 私钥文件路径。两者都设时覆盖 `private_key`。 |
private_key_passphrase | string | (unset) | <string> | 用于解锁加密私钥的 passphrase。 |
host_key | badoption.Listable[string] | [] | <key string> | 期望的主机密钥(authorized_keys 格式)。为空则不校验 —— 仅用于测试。 |
host_key_algorithms | badoption.Listable[string] | (library default) | <algo> | 限制客户端可接受的主机密钥算法。对旧服务器有用。 |
client_version | string | (library default) | <SSH version string> | 客户端版本横幅。可覆盖以伪装成 OpenSSH 或特定构建。 |
源码: option/ssh.go:5-16 · 锚定版本 v1.13.11 (553cfa1)
内嵌 DialerOptions 与 ServerOptions(server、server_port)。
示例
密钥鉴权,主机密钥已锚定:
json
{
"outbounds": [
{
"type": "ssh",
"tag": "ssh-out",
"server": "ssh.example.com",
"server_port": 22,
"user": "alice",
"private_key_path": "/etc/sing-box/id_ed25519",
"private_key_passphrase": "<passphrase>",
"host_key": ["ssh.example.com ssh-ed25519 AAAA..."]
}
]
}密码鉴权 + 横幅伪装:
json
{
"outbounds": [
{
"type": "ssh",
"tag": "ssh-spoof",
"server": "ssh.example.com",
"server_port": 22,
"user": "alice",
"password": "<password>",
"client_version": "SSH-2.0-OpenSSH_9.6"
}
]
}说明
- SSH 出站是 仅客户端 —— sing-box 不提供 SSH 服务端入站。
host_key为 OpenSSHknown_hosts风格。空值意味着「信任任意主机 密钥」—— 生产环境下不安全。private_key接受列表,便于主机轮换密钥;sing-box 会依次尝试, 直到有一项被接受。
跨内核说明
- Xray-core 不实现 SSH。参见 SSH — Xray-core。
- mihomo 使用
username(而非user),其余为 kebab-case (private-key-passphrase、host-key-algorithms),并把私钥作为 单字符串接收而非列表。参见 SSH — mihomo。
源码: option/ssh.go:5-16 · v1.13.11 (553cfa1)
