整理 OpenCode 常用 sshpass、OpenSSH、PuTTY/plink、WinSCP、MobaXterm、Termius、Tabby、XPipe 等 SSH 工具的适用场景,并说明怎么安全接入 OpenWrt / iStoreOS 排错。
内容更新 2026-05-25OpenCode 用 sshpass 可以解决密码输入卡住的问题,但长期最好换 SSH Key;真人排错再配 PuTTY、WinSCP、MobaXterm 这类图形工具。
openwrt-ssh 包装器;如果当前只能密码登录,先由真人带外核对 SSH 主机指纹并预置 known_hosts,再启用 sshpass 模式。sshpass -p 密码 参数里,改用 SSHPASS 环境变量。~/.ssh/config 里写 Host openwrt-router。sshpass 结束或报错后都清理环境变量,避免后续命令或截图暴露密码。# macOS:安装 sshpass 的常见方式之一
brew tap hudochenkov/sshpass
brew install hudochenkov/sshpass/sshpass
sshpass -V# OpenCode 用 sshpass 过渡登录:先由真人带外核对主机指纹并预置 known_hosts;
# wrapper 强制 StrictHostKeyChecking=yes。密码只放环境变量,异常时也自动清理。
cleanup() { unset SSHPASS OPENWRT_USE_SSHPASS; }
trap cleanup EXIT HUP INT TERM
export OPENWRT_HOST=openwrt-router
export OPENWRT_USE_SSHPASS=1
export SSHPASS='你的路由器密码'
openwrt-ssh ping
openwrt-ssh status
openwrt-ssh plugin-status# Windows PowerShell:如果已安装 sshpass.exe 并在 PATH 中
# 先由真人带外核对主机指纹并预置 known_hosts;wrapper 强制 StrictHostKeyChecking=yes。
$env:OPENWRT_HOST = "openwrt-router"
$env:OPENWRT_USE_SSHPASS = "1"
$env:SSHPASS = "你的路由器密码"
$Tool = "$env:USERPROFILE\bin\openwrt-ssh.ps1"
try {
# 先查看当前策略;Bypass 只对下面的子进程生效,不要持久修改 CurrentUser / LocalMachine
Get-ExecutionPolicy -List
powershell -NoProfile -ExecutionPolicy Bypass -File $Tool ping
if ($LASTEXITCODE -ne 0) { throw 'openwrt-ssh ping failed' }
powershell -NoProfile -ExecutionPolicy Bypass -File $Tool status
if ($LASTEXITCODE -ne 0) { throw 'openwrt-ssh status failed' }
} finally {
Remove-Item Env:\SSHPASS -ErrorAction SilentlyContinue
Remove-Item Env:\OPENWRT_USE_SSHPASS -ErrorAction SilentlyContinue
}# 长期方案:改成 SSH Key
ssh-keygen -t ed25519 -C "opencode-openwrt" -f ~/.ssh/openwrt_opencode
# 首次连接显示 fingerprint 时,先与路由器本机界面或本地控制台显示的主机指纹逐字比对;
# 无法带外核对就停止,不要确认主机密钥,也不要输入 root 密码。
cat ~/.ssh/openwrt_opencode.pub | ssh root@192.168.1.1 "umask 077; mkdir -p /etc/dropbear; cat >> /etc/dropbear/authorized_keys; chmod 600 /etc/dropbear/authorized_keys"
cat >> ~/.ssh/config <<'EOF'
Host openwrt-router
HostName 192.168.1.1
User root
IdentityFile ~/.ssh/openwrt_opencode
IdentitiesOnly yes
StrictHostKeyChecking yes
EOF
openwrt-ssh ping
ssh、scp、ssh-keygen、~/.ssh/config,适合自动化和长期维护。plink -batch 可以脚本化。/etc/config 或 OpenClash 配置。SSHPASS 环境变量,不写进命令、不写进提示词、不写进脚本文件。sshpass -p 明文密码 ssh ...。openwrt-ssh status、plugin-status、subscriptions。unset SSHPASS OPENWRT_USE_SSHPASS 或删除 PowerShell 环境变量。这段可以直接复制给 OpenCode,让它知道当前 SSH 方案和边界。
你不要直接打开交互式 ssh。当前如果需要密码登录,必须先确认真人已带外核对 SSH 主机指纹并预置 known_hosts;之后只能使用 sshpass 环境变量模式:OPENWRT_USE_SSHPASS=1 和 SSHPASS。不要使用 sshpass -p,不要输出密码,不要把密码写入文件。优先调用 openwrt-ssh ping、status、network、dns、plugin-status、subscriptions、plugin-logs。除 backup 外不要执行修改命令;若建议 plugin-repair,先展示证据、影响、维护窗口和回滚方案并等待我当次明确批准,且你不得设置 OPENWRT_ALLOW_REPAIR。
sshpass 过渡;长期用 SSH Key。ssh root@192.168.1.1 能连,但 Agent 卡在密码输入sshpass、PuTTY、WinSCP、MobaXterm 各自负责什么sshpass 可以把密码登录变成非交互命令,但密码处理不当会泄露sshpass,优先改 SSH Key;Homebrew 的 sshpass 可能需要额外 tap。sshpass.exe,可以先用 PuTTY/plink 或直接做 SSH Key。sshpass 不会生效,只能用 SSH Key。Host key verification failed,先人工确认设备身份,不要让 Agent 自动删 known_hosts。