kssh — Rust SSH 客户端 + 宝塔 API

kssh — Rust SSH 客户端 + 宝塔 API#

极简 SSH 客户端,带 60+ 宝塔子命令,纯 Rust 单二进制 7.1MB

安装#

git clone ... && cd kssh
cargo build --release
cp target/release/kssh /usr/local/bin/kssh

7 个 SSH 子命令#

kssh exec <target> -- <cmd>#

远程执行命令。target 格式 user@host

kssh exec root@139.224.208.63 -- df -h
kssh exec root@139.224.208.63 -- bash -c "cd /tmp && ls"

kssh put <target> <local> <remote>#

上传文件/目录,自动递归。

kssh put root@139 /tmp/app.tgz /www/wwwroot/app.tgz

kssh get / kssh ls / kssh cp / kssh which / kssh ping#

  • get: 下载
  • ls: 列目录
  • cp: 远程拷贝
  • which: 查命令路径
  • ping: 测连

60 个宝塔子命令 (节选)#

系统#

kssh bt http://139.224.208.63:23010 system
kssh bt http://139.224.208.63:23010 disk
kssh bt http://139.224.208.63:23010 load
kssh bt http://139.224.208.63:23010 boot

站点#

kssh bt $PANEL sites
kssh bt $PANEL site-add kus.z.h3hu.com /www/wwwroot/kus --kind=Python --php-ver=00
kssh bt $PANEL site-del 8 kus.z.h3hu.com --path
kssh bt $PANEL site-cmd api.z.h3hu.com stop
kssh bt $PANEL lets-encrypt kus.z.h3hu.com --method=http
kssh bt $PANEL conf-set kus.z.h3hu.com --file /tmp/proxy.conf

防火墙#

kssh bt $PANEL fw-list
kssh bt $PANEL fw-add 8765 --ps=python-app
kssh bt $PANEL fw-del 8765
kssh bt $PANEL ssh-info

计划任务#

kssh bt $PANEL cron-list
kssh bt $PANEL cron-add --expr '0 3 * * *' --cmd '/bin/df -h' --name=daily-df

凭据与白名单#

# 密钥存 ~/.config/kssh/bt/{host}.key
echo 'dRxPn1piHEICNBC6r11Kocbh9caCzZtA' > ~/.config/kssh/bt/139.224.208.63_23010.key
chmod 600 ~/.config/kssh/bt/139.224.208.63_23010.key
⚠ 宝塔 API 校验 IP,需在 /www/server/panel/config/api.jsonlimit_addr 加白名单。

签名算法#

request_token = md5( request_time + md5(api_sk) )
  • request_time: unix 秒
  • api_sk: api.jsontoken_crypt 字段(不是 key!)

参考#

  • 完整 60 子命令: <https://github.com/.../kssh/docs/USAGE.html>