Saltar al contenido principal
W

dsh-ssh-exec

wsy320/dsh-ssh-exec

Runs commands on remote hosts over SSH in-process, so password auth works without a terminal. Remote host passwords are read from a local hosts file in plain text (or from an environment variable named by passwordEnv).

Instalar

dsh plugin --profile web add github:wsy320/dsh-ssh-exec

README

dsh-ssh-exec

一个只做一件事的 DSH 插件:注册 ssh_exec 工具,让 agent 能在没有交互终端的环境里登录远程主机执行命令。

解决什么问题

DSH 的 shell 是非交互的:

[Console]::IsInputRedirected  = True
[Console]::IsOutputRedirected = True

原生 ssh 客户端读密码走终端接口(CONIN$),没有 tty 就永远等不到密码。表现出来的不是 Permission denied,而是命令原地挂死——不报错、不返回,直到超时被杀。echo 密码 | ssh ... 也没用,OpenSSH 不读 stdin 管道取密码。

本插件用 ssh2 在进程内直接讲 SSH 协议:不调用 ssh 二进制, 不需要 tty,密码认证可以正常工作。

与 dsh-ssh 的区别

dsh-sshdsh-ssh-exec
注册独立工具❌✅ ssh_exec
接管 ctx.subprocess / ctx.fs✅(整个会话搬到远程)❌ 本机 pwsh 与文件工具照常可用
适用远程开发工作区偶尔登录远程机器执行命令

两者可以共存;本插件不碰单槽位服务,因此不会改变本地执行环境。

安装

// ~/.dsh/profiles/<profile>/package.json
"dependencies": {
  "dsh-ssh-exec": "link:/path/to/dsh-ssh-exec"
},
"dsh": { "profile": { "bundles": [ /* … */ "dsh-ssh-exec" ] } }

然后在 profile 的 node_modules 里建立指向插件目录的符号链接(参考已有的 dsh-memory-vault), 重启 DSH。工具列表里会出现 ssh_exec。

主机表

默认读取 ~/.dsh/ssh_hosts.json(可用 hostsFile 配置项覆盖):

{
  "hosts": {
    "router": { "hostname": "192.168.1.1", "username": "root", "password": "…" },
    "nas":    { "hostname": "192.168.1.20", "username": "root", "passwordEnv": "NAS_PW",
                "via": "router" }
  }
}
字段说明
hostname port username连接目标,port 默认 22,username 默认 root
password明文密码
passwordEnv改从环境变量取密码,推荐;优先于 password
privateKey passphrase私钥路径或 PEM 内容;未配置时回退 ~/.ssh/id_ed25519,再回退 SSH agent
via跳板机别名,走 ssh2 的 forwardOut

不认识的 host 参数会被当成字面主机名/IP 直接连接。

工具参数

参数说明
actionrun(默认语义)或 list
host主机别名或 IP
command要执行的命令(run 必填)
timeout超时秒数,默认取配置 defaultTimeout(120)

返回一段文本:命令、stdout、stderr(非空时)、退出码;超过 maxOutput 会截断并标注。

配置项

字段默认说明
hostsFile~/.dsh/ssh_hosts.json主机表路径
defaultTimeout120默认超时(秒)
maxOutput200000单次返回最大字符数

已知限制

  • 每条命令独立建连,没有连接复用;高频调用会有握手开销。
  • 不做主机指纹校验(家用内网自签场景),如需严格校验可加 known_hosts 支持。
  • 远程 pid 不可见,无法定点杀进程;长任务请自带超时。

License

MIT

Plugins relacionados