Skip to content

Commit 2cd90fc

Browse files
feat: hide password config on first use
1 parent df40d52 commit 2cd90fc

14 files changed

Lines changed: 363 additions & 35 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<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>
1313
<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>
1414
<a href="https://github.com/sleepinginsummer/agent-ssh-cli"><img src="https://img.shields.io/badge/sys-win%2Fmac%2Flinux-0078D6" alt="sys win/mac/linux"></a>
15-
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.9-blue" alt="release v0.2.9"></a>
15+
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/releases"><img src="https://img.shields.io/badge/release-v0.3.0-blue" alt="release v0.3.0"></a>
1616
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen" alt="PRs welcome"></a>
1717
</p>
1818

@@ -88,7 +88,7 @@ AGENT_SSH_CONFIG=/path/to/config.json
8888
- `name`: 连接名,必须唯一
8989
- `host`: SSH 主机地址
9090
- `username`: SSH 用户名
91-
- `password` / `privateKey`: 认证方式,二者必须且只能配置一个
91+
- `password` / `passwordRef` / `privateKey`: 认证方式,密码、密码引用、私钥三类认证只能保留一种
9292
- `port`: SSH 端口,默认 `22`
9393
- `passphrase`: 私钥口令,仅配合 `privateKey` 使用
9494
- `pty`: 是否分配伪终端,默认 `false`,也可通过 `exec --pty` 临时开启
@@ -100,6 +100,8 @@ AGENT_SSH_CONFIG=/path/to/config.json
100100

101101
完整示例见 [example.config.json](example.config.json)`~/.agent-ssh-cli/config.json` 保存真实连接信息。
102102

103+
为防止配置文件中的密码泄露,密码认证会在第一次使用该服务器时被动加密保存:首次写入明文 `password` 后,执行 `exec``upload``download` 连接该服务器时,CLI 会把密码加密保存到配置目录下的 `secrets.json`,生成本地 `secret.key`,并把配置中的 `password` 置空、写入 `passwordRef`。后续运行通过 `passwordRef` 解密认证;如需修改密码,把空的 `password` 重新填成新密码,下次连接会自动覆盖旧密文。
104+
103105
参考配置
104106

105107
```json
@@ -109,7 +111,8 @@ AGENT_SSH_CONFIG=/path/to/config.json
109111
"host": "192.0.2.10",
110112
"port": 22,
111113
"username": "root",
112-
"password": "******",
114+
"password": "",
115+
"passwordRef": "agentsshcli:密码服务器",
113116
"commandBlacklist": [
114117
"(^|[;&|()\\s])rm(\\s|$)",
115118
"(^|[;&|()\\s])shutdown(\\s|$)",

README_EN.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Remote exec · File upload · File download · Connection config · Command whit
1212
<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>
1313
<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>
1414
<a href="https://github.com/sleepinginsummer/agent-ssh-cli"><img src="https://img.shields.io/badge/sys-win%2Fmac%2Flinux-0078D6" alt="sys win/mac/linux"></a>
15-
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/releases"><img src="https://img.shields.io/badge/release-v0.2.9-blue" alt="release v0.2.9"></a>
15+
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/releases"><img src="https://img.shields.io/badge/release-v0.3.0-blue" alt="release v0.3.0"></a>
1616
<a href="https://github.com/sleepinginsummer/agent-ssh-cli/pulls"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen" alt="PRs welcome"></a>
1717
</p>
1818

@@ -87,7 +87,7 @@ The configuration file is an array, and each item represents one server:
8787
- `name`: Connection name, must be unique
8888
- `host`: SSH host address
8989
- `username`: SSH username
90-
- `password` / `privateKey`: Authentication method; exactly one of the two must be configured
90+
- `password` / `passwordRef` / `privateKey`: Authentication method; keep exactly one authentication type among password, password reference, and private key
9191
- `port`: SSH port, defaults to `22`
9292
- `passphrase`: Private key passphrase, only used with `privateKey`
9393
- `pty`: Whether to allocate a pseudo-terminal, defaults to `false`; it can also be enabled per command with `exec --pty`
@@ -99,6 +99,8 @@ The configuration file is an array, and each item represents one server:
9999

100100
See the full example in [example.config.json](example.config.json). Store real connection information in `~/.agent-ssh-cli/config.json`.
101101

102+
To reduce password leakage from configuration files, password authentication is passively encrypted the first time that server is used: after you write a plaintext `password`, the next `exec`, `upload`, or `download` for that server encrypts the password into `secrets.json` under the config directory, creates a local `secret.key`, then writes the config back with an empty `password` and a `passwordRef`. Later runs decrypt through `passwordRef`. To change the password, replace the empty `password` with the new plaintext password; the next connection overwrites the old encrypted value.
103+
102104
Reference configuration
103105

104106
```json
@@ -108,7 +110,8 @@ Reference configuration
108110
"host": "192.0.2.10",
109111
"port": 22,
110112
"username": "root",
111-
"password": "******",
113+
"password": "",
114+
"passwordRef": "agentsshcli:password-server",
112115
"commandBlacklist": [
113116
"(^|[;&|()\\s])rm(\\s|$)",
114117
"(^|[;&|()\\s])shutdown(\\s|$)",

SKILL.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ mkdir -p ~/.agent-ssh-cli
8888
~/.agent-ssh-cli/config.json
8989
```
9090

91+
为防止配置文件中的密码泄露,密码认证会在第一次使用该服务器时被动加密保存:如果目标连接的 `password` 是非空明文,下一次执行 `exec``upload``download` 连接该服务器前,CLI 会把密码加密写入配置目录的 `secrets.json`,生成本地 `secret.key`,并把 `config.json` 中该连接改成 `password: ""``passwordRef`。改密码时直接把空的 `password` 重新填成新密码,下一次连接会自动覆盖旧密文。私钥认证不参与这个流程。
92+
93+
隐藏后的密码配置示例:
94+
95+
```json
96+
{
97+
"name": "server",
98+
"host": "192.0.2.10",
99+
"port": 22,
100+
"username": "root",
101+
"password": "",
102+
"passwordRef": "agentsshcli:server"
103+
}
104+
```
105+
91106
指定其它配置文件:
92107

93108
```bash

example.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"host": "192.0.2.10",
55
"port": 22,
66
"username": "root",
7-
"password": "******",
7+
"password": "",
8+
"passwordRef": "agentsshcli:密码服务器",
89
"allowedLocalPaths": [
910
"./tmp"
1011
],

native/Cargo.lock

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "agentsshcli-native"
3-
version = "0.2.9"
3+
version = "0.3.0"
44
edition = "2021"
55

66
[[bin]]
@@ -9,7 +9,10 @@ path = "src/main.rs"
99

1010
[dependencies]
1111
libc = "0.2"
12+
base64 = "0.22"
13+
chacha20poly1305 = "0.10"
1214
regex = "1"
15+
rand_core = { version = "0.6", features = ["getrandom"] }
1316
sha2 = "0.10"
1417
serde = { version = "1", features = ["derive"] }
1518
serde_json = "1"

0 commit comments

Comments
 (0)