Skip to content

SSH — sing-box

sing-box 提供 SSH 客户端出站。标准 SSH 特性 —— 密码鉴权、带 passphrase 的密钥鉴权、主机密钥锚定、横幅覆盖 —— 都已暴露。

出站

type: "ssh"

字段类型默认值允许值描述
userstring(server-dependent)<username>SSH 登录名。
passwordstring(unset)<string>密码鉴权。可与密钥鉴权并用 —— 两者都设时 sing-box 优先尝试密码。
private_keybadoption.Listable[string][]<PEM block>内联私钥。接受单个 PEM 字符串或 PEM 字符串列表。
private_key_pathstring(unset)<file path>私钥文件路径。两者都设时覆盖 `private_key`。
private_key_passphrasestring(unset)<string>用于解锁加密私钥的 passphrase。
host_keybadoption.Listable[string][]<key string>期望的主机密钥(authorized_keys 格式)。为空则不校验 —— 仅用于测试。
host_key_algorithmsbadoption.Listable[string](library default)<algo>限制客户端可接受的主机密钥算法。对旧服务器有用。
client_versionstring(library default)<SSH version string>客户端版本横幅。可覆盖以伪装成 OpenSSH 或特定构建。

源码: option/ssh.go:5-16 · 锚定版本 v1.13.11 (553cfa1)

内嵌 DialerOptionsServerOptionsserverserver_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 为 OpenSSH known_hosts 风格。空值意味着「信任任意主机 密钥」—— 生产环境下不安全。
  • private_key 接受列表,便于主机轮换密钥;sing-box 会依次尝试, 直到有一项被接受。

跨内核说明

  • Xray-core 不实现 SSH。参见 SSH — Xray-core
  • mihomo 使用 username(而非 user),其余为 kebab-case (private-key-passphrasehost-key-algorithms),并把私钥作为 单字符串接收而非列表。参见 SSH — mihomo

源码: option/ssh.go:5-16 · v1.13.11 (553cfa1)

由 Argsment 出品的 Core Tutorial