Skip to content

Commit f566858

Browse files
committed
增强了fssh init交互能力
1 parent 2fc3c9f commit f566858

File tree

12 files changed

+1611
-25
lines changed

12 files changed

+1611
-25
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"WebSearch",
88
"Bash(go build:*)",
99
"Bash(./fssh)",
10-
"Bash(./fssh status:*)"
10+
"Bash(./fssh status:*)",
11+
"Bash(tree:*)",
12+
"Bash(go doc:*)",
13+
"Bash(launchctl list:*)"
1114
],
1215
"deny": [],
1316
"ask": []

README.md

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,33 @@ Your SSH private keys are stored encrypted. They can only be decrypted after Tou
3737

3838
## Quick Start
3939

40-
### Step 1: Install
40+
### Option A: Interactive Setup Wizard (Recommended)
41+
42+
The easiest way to get started - one command does everything:
43+
44+
```bash
45+
# Build the project
46+
go build ./cmd/fssh
47+
48+
# Run interactive setup wizard
49+
./fssh init
50+
```
51+
52+
The wizard will guide you through:
53+
1. **Choose authentication mode** - Touch ID or OTP
54+
2. **Install binary** - Automatically copies fssh to /usr/local/bin
55+
3. **Import SSH keys** - Scans and imports keys from ~/.ssh/
56+
4. **Configure auto-start** - Sets up LaunchAgent for automatic startup
57+
5. **Start agent** - Launches fssh agent immediately
58+
6. **Configure SSH client** - Updates ~/.ssh/config automatically
59+
60+
After completion, you're ready to use SSH with Touch ID/OTP authentication!
61+
62+
### Option B: Manual Setup (Advanced)
63+
64+
For users who prefer step-by-step control:
65+
66+
#### Step 1: Install
4167

4268
```bash
4369
# After downloading the source code, build it
@@ -47,7 +73,7 @@ go build ./cmd/fssh
4773
sudo cp fssh /usr/local/bin/
4874
```
4975

50-
### Step 2: Initialize
76+
#### Step 2: Initialize
5177

5278
Choose an authentication mode based on your device:
5379

@@ -68,7 +94,7 @@ During OTP mode initialization:
6894
2. A TOTP secret will be displayed - add it to an authenticator app (e.g., Google Authenticator, Authy)
6995
3. 10 recovery codes will be shown - **save them securely**
7096

71-
### Step 3: Import SSH Private Key
97+
#### Step 3: Import SSH Private Key
7298

7399
```bash
74100
# Import your SSH private key (you'll be prompted for passphrase if the key has one)
@@ -80,15 +106,15 @@ Parameters:
80106
- `--file`: Path to the private key file
81107
- `--ask-passphrase`: Add this if the private key is passphrase-protected
82108

83-
### Step 4: Start the Agent
109+
#### Step 4: Start the Agent
84110

85111
```bash
86112
fssh agent
87113
```
88114

89115
Once started, the Agent runs in the background, listening on `~/.fssh/agent.sock`.
90116

91-
### Step 5: Configure SSH to Use fssh Agent
117+
#### Step 5: Configure SSH to Use fssh Agent
92118

93119
Edit `~/.ssh/config` and add at the **very beginning**:
94120

@@ -99,7 +125,7 @@ Host *
99125

100126
This routes all SSH connections through fssh Agent.
101127

102-
### Step 6: Start Using
128+
#### Step 6: Start Using
103129

104130
```bash
105131
# Use SSH normally - Touch ID or OTP prompt will appear automatically
@@ -108,6 +134,70 @@ ssh user@yourserver.com
108134

109135
---
110136

137+
## Interactive Setup Wizard Details
138+
139+
The interactive wizard (`fssh init`) performs the following steps:
140+
141+
### Step-by-step Process
142+
143+
**Step 1: Welcome & Initialization Check**
144+
- Displays welcome banner
145+
- Checks if fssh is already initialized
146+
- Prompts for confirmation if reinitializing
147+
148+
**Step 2: Choose Authentication Mode**
149+
- Auto-detects Touch ID availability on your Mac
150+
- Prompts you to choose between:
151+
- Touch ID (recommended for supported devices)
152+
- OTP (for devices without Touch ID or additional security)
153+
154+
**Step 3: Initialize Authentication**
155+
- Executes the selected authentication mode setup
156+
- For Touch ID: Generates and stores master key in macOS Keychain
157+
- For OTP: Sets up password + TOTP with recovery codes
158+
159+
**Step 4: Binary Installation**
160+
- Detects current executable location
161+
- Copies fssh to `/usr/local/bin/` (requires sudo)
162+
- Sets proper permissions (755)
163+
164+
**Step 5: Import SSH Keys**
165+
- Scans `~/.ssh/` directory for private keys
166+
- Detects standard key files: `id_rsa`, `id_ed25519`, `id_ecdsa`, etc.
167+
- Identifies encrypted vs unencrypted keys
168+
- Prompts for each key:
169+
- Suggested alias (e.g., `id_ed25519``ed25519`)
170+
- Passphrase if key is encrypted
171+
- Imports keys with encryption protection
172+
173+
**Step 6: Configure LaunchAgent**
174+
- Creates plist file at `~/Library/LaunchAgents/com.fssh.agent.plist`
175+
- Loads LaunchAgent for auto-start on login
176+
- Configures agent to keep running
177+
178+
**Step 7: Start Agent**
179+
- Waits for agent to start (up to 10 seconds)
180+
- Verifies socket connection at `~/.fssh/agent.sock`
181+
182+
**Step 8: Configure SSH Client**
183+
- Prompts to update `~/.ssh/config`
184+
- Creates backup before modification
185+
- Prepends `IdentityAgent` configuration for automatic SSH integration
186+
187+
### Non-Interactive Mode
188+
189+
For automation, scripts, or CI/CD:
190+
191+
```bash
192+
# Skip all interactive prompts
193+
fssh init --non-interactive --mode touchid
194+
195+
# Or specify mode directly
196+
fssh init --mode otp
197+
```
198+
199+
---
200+
111201
## Auto-Start on Login
112202

113203
Tired of manually starting the Agent after each reboot? Set up auto-start:
@@ -161,14 +251,29 @@ fssh> exit # Exit the shell
161251

162252
## Command Reference
163253

254+
### Initialization Commands
255+
256+
| Command | Description |
257+
|---------|-------------|
258+
| `fssh init` | Interactive setup wizard (recommended) |
259+
| `fssh init --interactive` | Explicitly run interactive wizard |
260+
| `fssh init --mode touchid` | Initialize with Touch ID (non-interactive) |
261+
| `fssh init --mode otp` | Initialize with OTP (non-interactive) |
262+
| `fssh init --non-interactive --mode touchid` | Non-interactive mode for scripts/CI |
263+
264+
### Key Management
265+
164266
| Command | Description |
165267
|---------|-------------|
166-
| `fssh init --mode touchid` | Initialize (Touch ID mode) |
167-
| `fssh init --mode otp` | Initialize (OTP mode) |
168268
| `fssh import --alias name --file path --ask-passphrase` | Import a private key |
169269
| `fssh list` | List imported keys |
170270
| `fssh export --alias name --out path` | Export a key (backup) |
171271
| `fssh remove --alias name` | Remove a key |
272+
273+
### Agent & Shell
274+
275+
| Command | Description |
276+
|---------|-------------|
172277
| `fssh agent` | Start the Agent |
173278
| `fssh status` | Check status |
174279
| `fssh shell` | Enter interactive shell |

README_CN.md

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,33 @@ fssh 是一个 macOS 专用的 SSH 密钥管理工具,解决两个痛点:
3636

3737
## 快速开始
3838

39-
### 第一步:安装
39+
### 方式一:交互式设置向导(推荐)
40+
41+
最简单的开始方式 - 一条命令搞定所有配置:
42+
43+
```bash
44+
# 编译项目
45+
go build ./cmd/fssh
46+
47+
# 运行交互式设置向导
48+
./fssh init
49+
```
50+
51+
向导会引导你完成:
52+
1. **选择认证模式** - Touch ID 或 OTP
53+
2. **安装二进制文件** - 自动复制 fssh 到 /usr/local/bin
54+
3. **导入 SSH 密钥** - 扫描并导入 ~/.ssh/ 下的密钥
55+
4. **配置开机自启** - 设置 LaunchAgent 自动启动
56+
5. **启动 agent** - 立即启动 fssh agent
57+
6. **配置 SSH 客户端** - 自动更新 ~/.ssh/config
58+
59+
完成后,你就可以直接使用 SSH 并通过 Touch ID/OTP 认证了!
60+
61+
### 方式二:手动设置(进阶)
62+
63+
适合希望逐步控制每个环节的用户:
64+
65+
#### 第一步:安装
4066

4167
```bash
4268
# 下载源码后,编译
@@ -46,7 +72,7 @@ go build ./cmd/fssh
4672
sudo cp fssh /usr/local/bin/
4773
```
4874

49-
### 第二步:初始化
75+
#### 第二步:初始化
5076

5177
根据你的设备选择认证模式:
5278

@@ -67,7 +93,7 @@ OTP 模式初始化时会:
6793
2. 显示 TOTP 密钥,需要添加到手机的验证器 App(如 Google Authenticator、Authy)
6894
3. 显示 10 个恢复码,**请务必保存好**
6995

70-
### 第三步:导入 SSH 私钥
96+
#### 第三步:导入 SSH 私钥
7197

7298
```bash
7399
# 导入你的 SSH 私钥(如果私钥有密码,会提示输入)
@@ -79,15 +105,15 @@ fssh import --alias mykey --file ~/.ssh/id_rsa --ask-passphrase
79105
- `--file`:私钥文件路径
80106
- `--ask-passphrase`:如果私钥有密码保护,加上这个参数
81107

82-
### 第四步:启动 Agent
108+
#### 第四步:启动 Agent
83109

84110
```bash
85111
fssh agent
86112
```
87113

88114
启动后,Agent 会在后台运行,监听 `~/.fssh/agent.sock`
89115

90-
### 第五步:配置 SSH 使用 fssh Agent
116+
#### 第五步:配置 SSH 使用 fssh Agent
91117

92118
编辑 `~/.ssh/config` 文件,在**最开头**添加:
93119

@@ -98,7 +124,7 @@ Host *
98124

99125
这样所有 SSH 连接都会通过 fssh Agent。
100126

101-
### 第六步:开始使用
127+
#### 第六步:开始使用
102128

103129
```bash
104130
# 正常使用 SSH 命令,会自动弹出 Touch ID 或要求输入 OTP
@@ -107,6 +133,70 @@ ssh user@yourserver.com
107133

108134
---
109135

136+
## 交互式设置向导详解
137+
138+
交互式向导(`fssh init`)会执行以下步骤:
139+
140+
### 详细流程
141+
142+
**步骤 1:欢迎和初始化检查**
143+
- 显示欢迎横幅
144+
- 检查是否已经初始化过
145+
- 如果需要重新初始化,会提示确认
146+
147+
**步骤 2:选择认证模式**
148+
- 自动检测你的 Mac 是否支持 Touch ID
149+
- 提示选择:
150+
- Touch ID(推荐用于支持的设备)
151+
- OTP(适用于不支持 Touch ID 的设备或需要额外安全性)
152+
153+
**步骤 3:执行认证初始化**
154+
- 执行所选认证模式的设置
155+
- Touch ID 模式:生成主密钥并存储到 macOS 钥匙串
156+
- OTP 模式:设置密码 + TOTP,生成恢复码
157+
158+
**步骤 4:安装二进制文件**
159+
- 检测当前可执行文件位置
160+
- 复制 fssh 到 `/usr/local/bin/`(需要 sudo)
161+
- 设置正确的权限(755)
162+
163+
**步骤 5:导入 SSH 密钥**
164+
- 扫描 `~/.ssh/` 目录查找私钥
165+
- 检测标准密钥文件:`id_rsa``id_ed25519``id_ecdsa`
166+
- 识别加密和未加密的密钥
167+
- 逐个提示导入:
168+
- 建议的别名(例如 `id_ed25519``ed25519`
169+
- 如果密钥加密,提示输入密码
170+
- 使用加密保护导入密钥
171+
172+
**步骤 6:配置 LaunchAgent**
173+
-`~/Library/LaunchAgents/com.fssh.agent.plist` 创建 plist 文件
174+
- 加载 LaunchAgent 实现登录时自动启动
175+
- 配置 agent 持续运行
176+
177+
**步骤 7:启动 Agent**
178+
- 等待 agent 启动(最多 10 秒)
179+
- 验证 `~/.fssh/agent.sock` 的 socket 连接
180+
181+
**步骤 8:配置 SSH 客户端**
182+
- 提示更新 `~/.ssh/config`
183+
- 修改前创建备份
184+
- 在开头添加 `IdentityAgent` 配置以实现 SSH 自动集成
185+
186+
### 非交互模式
187+
188+
适用于自动化、脚本或 CI/CD:
189+
190+
```bash
191+
# 跳过所有交互式提示
192+
fssh init --non-interactive --mode touchid
193+
194+
# 或直接指定模式
195+
fssh init --mode otp
196+
```
197+
198+
---
199+
110200
## 设置开机自启动
111201

112202
每次开机后手动启动 Agent 太麻烦?设置自启动:
@@ -160,14 +250,29 @@ fssh> exit # 退出
160250

161251
## 常用命令一览
162252

253+
### 初始化命令
254+
255+
| 命令 | 说明 |
256+
|------|------|
257+
| `fssh init` | 交互式设置向导(推荐) |
258+
| `fssh init --interactive` | 显式运行交互式向导 |
259+
| `fssh init --mode touchid` | 使用 Touch ID 初始化(非交互式) |
260+
| `fssh init --mode otp` | 使用 OTP 初始化(非交互式) |
261+
| `fssh init --non-interactive --mode touchid` | 非交互模式,适用于脚本/CI |
262+
263+
### 密钥管理
264+
163265
| 命令 | 说明 |
164266
|------|------|
165-
| `fssh init --mode touchid` | 初始化(Touch ID 模式) |
166-
| `fssh init --mode otp` | 初始化(OTP 模式) |
167267
| `fssh import --alias 名字 --file 路径 --ask-passphrase` | 导入私钥 |
168268
| `fssh list` | 列出已导入的密钥 |
169269
| `fssh export --alias 名字 --out 路径` | 导出密钥(备份) |
170270
| `fssh remove --alias 名字` | 删除密钥 |
271+
272+
### Agent 和 Shell
273+
274+
| 命令 | 说明 |
275+
|------|------|
171276
| `fssh agent` | 启动 Agent |
172277
| `fssh status` | 查看状态 |
173278
| `fssh shell` | 进入交互式 Shell |

0 commit comments

Comments
 (0)