# ssh-cli **Repository Path**: FLiuYi/ssh-cli ## Basic Information - **Project Name**: ssh-cli - **Description**: ssh-cli工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-14 - **Last Updated**: 2026-03-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ssh-tool SSH命令行工具,专为AI调用场景优化。 ## 安装 ```bash # 克隆项目 git clone https://gitee.com/FLiuYi/ssh-cli.git cd ssh-cli # 安装依赖 npm install # 本地链接 npm link ``` ## 更新 ```bash cd ssh-cli git pull npm install npm link ``` ## 配置文件 默认配置文件路径:`~/.ssh-tool/config.json` ```json { "default": { "host": "default-server.com", "port": 22, "username": "default-user", "privateKey": "~/.ssh/id_rsa", "passphrase": "your-key-passphrase", "knownHosts": "~/.ssh/known_hosts", "timeout": 60 }, "profiles": { "production": { "host": "prod-server.com", "port": 22, "username": "admin", "privateKey": "~/.ssh/prod_key", "timeout": 120 }, "staging": { "host": "staging-server.com", "port": 2222, "username": "staging-user", "password": "staging-pass", "timeout": 60 }, "key-auth": { "host": "key-server.com", "username": "ubuntu", "privateKey": "~/.ssh/id_ed25519", "passphrase": "optional-passphrase", "knownHosts": "~/.ssh/known_hosts" } } } ``` ### 配置字段说明 | 字段 | 说明 | |------|------| | `host` | SSH服务器地址 | | `port` | SSH端口,默认22 | | `username` | SSH用户名 | | `password` | 密码认证 | | `privateKey` | 私钥文件路径(支持~/.ssh/等缩写) | | `passphrase` | 私钥密码(如有) | | `knownHosts` | known_hosts文件路径 | | `timeout` | 连接超时时间(秒) | ## 使用方式 ### 命令执行 ```bash # 方式1: 命令行参数 ssh-tool exec "ls -la" --host 101.42.188.100 -u root --password "your-password" # 方式2: 使用profile ssh-tool exec "ls -la" --profile production # 方式3: 环境变量 export SSH_PROFILE=staging ssh-tool exec "ls -la" # JSON输出(AI推荐使用) ssh-tool exec "ls -la" --host 101.42.188.100 -u root --password "your-password" --json ``` ### 文件上传 ```bash ssh-tool upload /local/path /remote/path --host 101.42.188.100 -u root --password "your-password" ``` ### 文件下载 ```bash ssh-tool download /remote/path /local/path --host 101.42.188.100 -u root --password "your-password" ``` ## 参数说明 | 参数 | 简写 | 说明 | 默认值 | |------|------|------|--------| | `--host` | -h | 远程主机地址 | - | | `--port` | -p | SSH端口 | 22 | | `--username` | -u | 用户名 | - | | `--password` | - | 密码 | - | | `--private-key` | - | 私钥路径 | - | | `--passphrase` | - | 私钥密码 | - | | `--known-hosts` | - | known_hosts路径 | - | | `--config` | - | 配置文件路径 | ~/.ssh-tool/config.json | | `--profile` | - | profile名称 | - | | `--timeout` | - | 超时秒数 | 60 | | `--json` | - | JSON输出 | false | ## 配置优先级 1. 命令行参数(最高) 2. `--profile` 指定 3. `SSH_PROFILE` 环境变量 4. `default` 配置 5. 程序默认值(最低) ## JSON输出格式 ```json { "code": 0, "stdout": "命令标准输出", "stderr": "命令错误输出", "duration": 1.23, "success": true } ``` 字段说明: - `code`: 退出码(0为成功) - `stdout`: 标准输出 - `stderr`: 错误输出 - `duration`: 执行耗时(秒) - `success`: 是否成功 ## 注意事项 - 仅支持非交互式命令 - 每次执行后自动关闭连接 - 密码和私钥二选一