agent-ssh-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 syy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ <div align="center">
2
+
3
+ # agent-ssh-cli
4
+
5
+ 基于 CLI 的 SSH 代理工具,按 ssh-mcp-server 的能力映射为 Agent 可调用的远端操作能力。
6
+
7
+ 远程执行 · 文件上传 · 文件下载 · 连接配置 · 命令白名单 · 命令黑名单 · Agent Skill 集成
8
+
9
+ <p>
10
+ <a href="https://github.com/sleepinginsummer/agent-ssh-cli"><img src="https://img.shields.io/badge/CLI-agentsshcli-2ea44f" alt="CLI agentsshcli"></a>
11
+ <a href="https://github.com/sleepinginsummer/agent-ssh-cli/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License MIT"></a>
12
+ <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-%3E%3D18-339933?logo=node.js&logoColor=white" alt="Node.js >=18"></a>
13
+ <a href="https://www.npmjs.com/"><img src="https://img.shields.io/badge/npm-%3E%3D8-CB3837?logo=npm&logoColor=white" alt="npm >=8"></a>
14
+ <a href="https://github.com/sleepinginsummer/agent-ssh-cli/releases"><img src="https://img.shields.io/badge/release-v0.1.0-blue" alt="release v0.1.0"></a>
15
+ <a href="https://github.com/sleepinginsummer/agent-ssh-cli/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen" alt="PRs welcome"></a>
16
+ </p>
17
+
18
+ [AI 一键安装](#ai-一键安装) · [手动安装](#手动安装) · [配置](#配置) · [卸载和清理](#卸载和清理) · [许可证](#许可证) · [友情链接](#友情链接)
19
+
20
+ 中文 | [English](README_EN.md)
21
+
22
+ </div>
23
+
24
+ ## 简介
25
+ 本项目参考 [classfang/ssh-mcp-server](https://github.com/classfang/ssh-mcp-server) 的 SSH 操作能力设计,改写为独立 CLI 形式。感谢原项目提供的思路和能力基础。
26
+
27
+ #### 他能做的事:
28
+ - 解放双手,自动运维服务器
29
+ - 部署代码,更新部署docker
30
+ - 配置nginx,配置证书
31
+ - 所有ssh能做到的事情
32
+ #### 他的能力:
33
+ - 列出本地配置中的 SSH 服务器连接
34
+ - 在指定远端服务器上执行命令
35
+ - 上传本地文件到远端服务器
36
+ - 从远端服务器下载文件到本地
37
+ - 通过命令黑白名单限制可执行命令
38
+ - 通过本地路径白名单限制上传和下载访问范围
39
+
40
+ ## AI 一键安装
41
+
42
+ ```
43
+ 安装请阅读 https://github.com/sleepinginsummer/agent-ssh-cli/blob/main/AI_INSTALL.md,按说明安装 CLI 并添加 `SKILL.md`。
44
+ ```
45
+
46
+ ## 手动安装
47
+ ### 环境要求
48
+
49
+ - Node.js `>= 18`
50
+ - npm `>= 8`
51
+ - 本机网络可访问目标 SSH 服务器
52
+ - 目标服务器已开启 SSH 服务
53
+ - 如使用私钥认证,私钥文件需对当前用户可读
54
+ - `agentsshcli exec/upload/download` 的连接缓存支持 macOS/Linux/Windows
55
+
56
+ ### 安装步骤
57
+
58
+ 1. 全局安装:
59
+
60
+ ```bash
61
+ npm install -g agent-ssh-cli
62
+ agentsshcli --help
63
+ ```
64
+
65
+ 2. 导入 SKILL.md:
66
+
67
+ 打开 [SKILL.md](SKILL.md),将其添加到 agent 中。
68
+
69
+ ## 配置
70
+
71
+ 初始化配置(格式参数和ssh-mcp-server一致):
72
+
73
+ ```bash
74
+ mkdir -p ~/.agent-ssh-cli
75
+ ```
76
+
77
+ 编辑 `~/.agent-ssh-cli/config.json`,填写真实连接信息。默认配置文件也可以通过环境变量覆盖:
78
+
79
+ 可以通过以下环境变量修改配置地点
80
+ ```bash
81
+ AGENT_SSH_CONFIG=/path/to/config.json
82
+ ```
83
+
84
+ 配置文件是数组,每一项是一台服务器:
85
+
86
+ - `name`: 连接名,必须唯一
87
+ - `host`: SSH 主机地址
88
+ - `username`: SSH 用户名
89
+ - `password` / `privateKey` / `agent`: 认证方式,三者必须且只能配置一个
90
+ - `port`: SSH 端口,默认 `22`
91
+ - `passphrase`: 私钥口令,仅配合 `privateKey` 使用
92
+ - `pty`: 是否分配伪终端,默认 `true`
93
+ - `allowedLocalPaths`: 额外允许上传或下载写入的本地路径
94
+ - `commandWhitelist`: 命令白名单正则数组
95
+ - `commandBlacklist`: 命令黑名单正则数组
96
+
97
+ `commandWhitelist` 和 `commandBlacklist` 使用 JavaScript `RegExp` 语法,不是 POSIX 正则;空白字符请写成 `\\s`,不要写 `[:space:]`。
98
+
99
+ 完整示例见 [example.config.json](example.config.json)。`~/.agent-ssh-cli/config.json` 保存真实连接信息。
100
+
101
+ 参考配置
102
+
103
+ ```json
104
+ [
105
+ {
106
+ "name": "密码服务器",
107
+ "host": "192.0.2.10",
108
+ "port": 22,
109
+ "username": "root",
110
+ "password": "******",
111
+ "commandBlacklist": [
112
+ "(^|[;&|()\\s])rm(\\s|$)",
113
+ "(^|[;&|()\\s])shutdown(\\s|$)",
114
+ "(^|[;&|()\\s])reboot(\\s|$)"
115
+ ]
116
+ },
117
+ {
118
+ "name": "密钥服务器",
119
+ "host": "198.51.100.10",
120
+ "port": 22,
121
+ "username": "deploy",
122
+ "privateKey": "/path/to/id_rsa",
123
+ "passphrase": "******",
124
+ "pty": false,
125
+ "allowedLocalPaths": [
126
+ "./tmp",
127
+ "./dist"
128
+ ],
129
+ "commandWhitelist": [
130
+ "^pwd$",
131
+ "^ls(\\s|$)",
132
+ "^cat\\s+/var/log/app\\.log$"
133
+ ],
134
+ "commandBlacklist": [
135
+ "(^|[;&|()\\s])rm(\\s|$)",
136
+ "(^|[;&|()\\s])shutdown(\\s|$)",
137
+ "(^|[;&|()\\s])reboot(\\s|$)"
138
+ ]
139
+ }
140
+ ]
141
+ ```
142
+
143
+
144
+
145
+ 测试命令
146
+
147
+ ```bash
148
+ agentsshcli list
149
+ ```
150
+
151
+ 完成安装!
152
+
153
+ ## 卸载和清理
154
+
155
+ ```bash
156
+ npm uninstall -g agent-ssh-cli
157
+ npm cache clean --force
158
+ #删除配置文件
159
+ rm -rf ~/.agent-ssh-cli
160
+ ```
161
+
162
+ ## 许可证
163
+
164
+ [MIT](LICENSE)
165
+
166
+ ## 友情链接
167
+
168
+ - [LINUX DO - 新的理想型社区](https://linux.do/)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runAgentSshCli } from "../src/cli.js";
3
+
4
+ runAgentSshCli(process.argv.slice(2)).catch((error) => {
5
+ console.error(error.message);
6
+ process.exit(1);
7
+ });
@@ -0,0 +1,40 @@
1
+ [
2
+ {
3
+ "name": "密码服务器",
4
+ "host": "192.0.2.10",
5
+ "port": 22,
6
+ "username": "root",
7
+ "password": "******",
8
+ "allowedLocalPaths": [
9
+ "./tmp"
10
+ ],
11
+ "commandBlacklist": [
12
+ "(^|[;&|()\\s])rm(\\s|$)",
13
+ "(^|[;&|()\\s])shutdown(\\s|$)",
14
+ "(^|[;&|()\\s])reboot(\\s|$)"
15
+ ]
16
+ },
17
+ {
18
+ "name": "密钥服务器",
19
+ "host": "198.51.100.10",
20
+ "port": 22,
21
+ "username": "deploy",
22
+ "privateKey": "/path/to/id_rsa",
23
+ "passphrase": "******",
24
+ "pty": false,
25
+ "allowedLocalPaths": [
26
+ "./tmp",
27
+ "./dist"
28
+ ],
29
+ "commandWhitelist": [
30
+ "^pwd$",
31
+ "^ls(\\s|$)",
32
+ "^cat\\s+/var/log/app\\.log$"
33
+ ],
34
+ "commandBlacklist": [
35
+ "(^|[;&|()\\s])rm(\\s|$)",
36
+ "(^|[;&|()\\s])shutdown(\\s|$)",
37
+ "(^|[;&|()\\s])reboot(\\s|$)"
38
+ ]
39
+ }
40
+ ]
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "agent-ssh-cli",
3
+ "version": "0.1.0",
4
+ "description": "基于 CLI 的 SSH 代理工具,按 ssh-mcp-server 的能力一一映射",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=18",
8
+ "npm": ">=8"
9
+ },
10
+ "files": [
11
+ "bin/",
12
+ "src/",
13
+ "example.config.json",
14
+ "README.md"
15
+ ],
16
+ "bin": {
17
+ "agentsshcli": "bin/agentsshcli.js"
18
+ },
19
+ "scripts": {
20
+ "test": "node --check bin/agentsshcli.js && node --check src/cli.js && node --check src/config.js && node --check src/daemon-client.js && node --check src/daemon-paths.js && node --check src/ssh-client.js && node --check src/ssh-daemon.js"
21
+ },
22
+ "dependencies": {
23
+ "ssh2": "^1.17.0"
24
+ }
25
+ }