npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sshm-cli

v1.0.6

Published

SSH Server Manager CLI - Securely manage SSH connections with jump host support

Readme

sshm - SSH Server Manager CLI

一个安全的 SSH 服务器管理命令行工具,支持跳板机连接、批量执行命令,专为 AI 接入设计。

特性

  • 🔐 安全存储 - AES-256-GCM 加密所有密码,PBKDF2 密钥派生
  • 🏢 分组管理 - 按组组织服务器,支持组级跳板机
  • 🚀 跳板机支持 - 通过 SSH 隧道连接内网服务器
  • 📋 批量导入 - JSON 文件批量添加服务器
  • 批量执行 - 并发在多台服务器执行命令
  • 🛡️ 安全策略 - 危险命令黑名单 + 命令模板双重保护
  • 📝 审计日志 - 记录所有执行历史

安装

从源码安装

# 克隆仓库
git clone <repository-url>
cd ssh-secure-cli

# 安装依赖
npm install

# 构建
npm run build

# 全局安装(可选)
npm link

系统要求

  • Node.js >= 18.0.0
  • npm >= 8.0.0

快速开始

1. 首次运行

首次运行时会提示设置主密码:

sshm --help
╔══════════════════════════════════════════════════════════════════╗
║  ⚠️  IMPORTANT: Master Password Security                           ║
╠══════════════════════════════════════════════════════════════════╣
║                                                                    ║
║  Your master password is used to encrypt all SSH credentials.     ║
║  If you lose this password, ALL stored credentials will be        ║
║  PERMANENTLY INACCESSIBLE. There is NO recovery mechanism.        ║
║                                                                    ║
╚══════════════════════════════════════════════════════════════════╝

⚠️ 重要: 请妥善保管主密码!丢失后将无法恢复任何存储的凭证。

2. 环境变量配置

可以通过环境变量提供主密码,避免交互式输入:

export SSHM_MASTER_PASSWORD="your-secure-password"

3. 基本使用流程

# 1. 添加跳板机(可选)
sshm jump-host add prod-jump --host jump.example.com --user admin

# 2. 创建服务器组
sshm group add production --jump-host prod-jump

# 3. 添加服务器
sshm connection add web-01 --group production --host 192.168.1.10 --user deploy

# 4. 执行命令
sshm exec web-01 --command "uptime"

命令参考

跳板机管理 (jump-host, jh)

# 添加跳板机
sshm jh add <name> --host <host> --user <user> [--port 22] [--description "desc"]

# 列出所有跳板机
sshm jh list

# 查看详情
sshm jh show <name>

# 更新跳板机
sshm jh update <name> --host <new-host>

# 测试连接
sshm jh test <name>

# 删除跳板机
sshm jh remove <name>

组管理 (group, g)

# 创建组(可指定默认跳板机)
sshm group add <name> [--jump-host <jump-host-name>]

# 列出所有组
sshm group list

# 查看组详情(包含组内服务器)
sshm group show <name>

# 更新组
sshm group update <name> [--new-name <new-name>] [--jump-host <jump-host>]

# 删除组(会删除组内所有服务器)
sshm group remove <name>

连接管理 (connection, conn, c)

# 添加连接
sshm conn add <name> \
  --group <group> \
  --host <host> \
  --user <user> \
  [--port 22] \
  [--environment <env>] \
  [--jump-host <jump-host>]

# 批量导入
sshm conn import servers.json

# 列出连接
sshm conn list [--group <group>] [--environment <env>]

# 查看详情
sshm conn show <name>

# 更新连接
sshm conn update <name> [--host <new-host>] [--user <new-user>] [--environment <env>]

# 测试连接
sshm conn test <name>

# 删除连接
sshm conn remove <name>

环境标识

每台服务器可以指定环境标识(dev/test/pre/prod),便于区分和管理:

# 添加服务器时指定环境
sshm conn add prod-server-1 --group production --host 192.168.1.10 --user deploy --environment prod

# 按环境筛选服务器列表
sshm conn list --environment prod

# 按环境批量执行命令
sshm exec @env:prod --template @sys:disk

支持的环境:

  • dev - 开发环境(默认)
  • test - 测试环境
  • pre - 预发布环境
  • prod - 生产环境

命令执行 (exec)

# 单机执行
sshm exec <server-name> --command "uptime"

# 批量执行(使用 @group 语法)
sshm exec @production --command "df -h"

# 使用命令模板
sshm exec <server> --template @sys:disk
sshm exec <server> -t @docker:ps

# 并发控制
sshm exec @production --command "uptime" --concurrency 10

# 超时设置
sshm exec <server> --command "long-running-script.sh" --timeout 120000

# JSON 输出
sshm exec @production --command "hostname" --json

# 允许危险命令
sshm exec <server> --command "rm -rf /tmp/*" --dangerous

执行日志

# 查看执行日志
sshm exec logs [--limit 50]

# JSON 格式输出
sshm exec logs --json

命令模板

# 列出可用模板
sshm exec templates

# 按分类筛选
sshm exec templates --category docker

黑名单管理

# 查看黑名单
sshm exec blacklist

# 添加黑名单规则
sshm exec blacklist --add "^rm\\s+-rf"

批量导入格式

JSON 文件格式:

{
  "group": "production",
  "jumpHost": "prod-jump",
  "servers": [
    {
      "name": "web-01",
      "host": "192.168.1.10",
      "port": 22,
      "user": "deploy",
      "password": "secret123",
      "environment": "prod"
    },
    {
      "name": "web-02",
      "host": "192.168.1.11",
      "user": "deploy",
      "password": "secret456",
      "environment": "prod"
    }
  ]
}

命令模板

内置安全命令模板,无需 --dangerous 标志:

系统状态

| 模板 | 命令 | 描述 | |------|------|------| | @sys:disk | df -h | 磁盘使用情况 | | @sys:memory | free -m | 内存使用情况 | | @sys:cpu | top -bn1 \| head -5 | CPU 使用情况 | | @sys:uptime | uptime | 系统运行时间 | | @sys:load | cat /proc/loadavg | 系统负载 |

进程管理

| 模板 | 命令 | 描述 | |------|------|------| | @proc:list | ps aux --sort=-%mem \| head -20 | 内存占用最高的进程 | | @proc:top-cpu | ps aux --sort=-%cpu \| head -10 | CPU 占用最高的进程 |

网络

| 模板 | 命令 | 描述 | |------|------|------| | @net:ports | netstat -tlnp | 监听端口 | | @net:connections | netstat -an \| grep ESTABLISHED | 活动连接 | | @net:interfaces | ip addr show | 网络接口 |

Docker

| 模板 | 命令 | 描述 | |------|------|------| | @docker:ps | docker ps -a | 所有容器 | | @docker:stats | docker stats --no-stream | 容器资源使用 | | @docker:logs | docker logs --tail 100 <container> | 容器日志 |

安全策略

密码加密

  • 算法: AES-256-GCM
  • 密钥派生: PBKDF2 (100,000 迭代)
  • 文件权限: 数据库 0600,目录 0700

命令安全

  1. 黑名单检测: 自动拦截危险命令

    # 这些命令会被拦截
    rm -rf /
    mkfs.ext4 /dev/sda1
    dd if=/dev/zero of=/dev/sda
    shutdown
    reboot
  2. Shell 元字符检测: 拦截管道、重定向等

    # 这些会被拦截
    ls | rm
    cat /etc/passwd > /tmp/passwd
    cmd1 && cmd2
  3. 自由命令: 需要 --dangerous 标志确认

审计日志

所有执行的命令都会记录,敏感信息自动脱敏:

  • 执行时间
  • 目标服务器
  • 命令内容(脱敏)
  • 执行结果
  • 退出码

配置

数据目录

默认数据目录: ~/.sshm/

~/.sshm/
├── connections.db      # SQLite 数据库
├── connections.db-wal  # WAL 日志
├── connections.db-shm  # 共享内存
├── .master_key         # 主密钥验证文件
└── .verification       # 密码验证数据

环境变量

| 变量 | 描述 | |------|------| | SSHM_MASTER_PASSWORD | 主密码(非交互模式) | | SSHM_DATA_DIR | 自定义数据目录 |

AI 接入指南

设计目标

本工具专为 AI 安全接入服务器设计:

  1. 不暴露密码: AI 只需调用 CLI,无需知道实际密码
  2. 命令审计: 所有操作可追溯
  3. 安全限制: 黑名单防止危险操作

使用示例

# AI 执行安全检查
sshm exec @all --template @sys:disk --json

# AI 检查服务状态
sshm exec web-server --template @docker:ps

# AI 收集日志
sshm exec @production --template @sys:uptime --json

推荐做法

  1. 使用环境变量 SSHM_MASTER_PASSWORD 避免交互
  2. 优先使用命令模板 (--template)
  3. 使用 --json 输出便于解析
  4. 限制 AI 可访问的服务器组

开发

# 开发模式
npm run dev

# 运行测试
npm test

# 构建
npm run build

# 代码检查
npm run lint

故障排除

连接失败

# 测试跳板机连接
sshm jh test <jump-host>

# 测试目标服务器连接
sshm conn test <server>

主密码问题

如果忘记主密码,需要:

  1. 删除 ~/.sshm/ 目录
  2. 重新初始化
  3. 重新添加所有服务器

权限问题

确保数据目录权限正确:

chmod 700 ~/.sshm
chmod 600 ~/.sshm/connections.db

许可证

MIT