` 连接
**额外 SSH 选项:**
你可以在交互式表单的 "SSH Options" 字段中添加任何有效的 SSH 选项。以命令行格式输入(如 `-o Compression=yes -o ServerAliveInterval=60`),ctty 会自动转换为正确的 SSH 配置格式。
**常用 SSH 选项:**
- `Compression` - 启用/禁用压缩(`yes`/`no`)
- `ServerAliveInterval` - 保活消息间隔(秒)
- `ServerAliveCountMax` - 保活消息最大数量
- `StrictHostKeyChecking` - 主机密钥验证(`yes`/`no`/`ask`)
- `UserKnownHostsFile` - known_hosts 文件路径
- `BatchMode` - 禁用交互式提示(`yes`/`no`)
- `ConnectTimeout` - 连接超时(秒)
- `ControlMaster` - 连接多路复用(`yes`/`no`/`auto`)
- `ControlPath` - 控制套接字路径
- `ControlPersist` - 保持连接存活时长
- `ForwardAgent` - 转发 SSH agent(`yes`/`no`)
- `LocalForward` - 本地端口转发(如 `8080:localhost:80`)
- `RemoteForward` - 远程端口转发
- `DynamicForward` - SOCKS 代理端口转发
**表单中的示例用法:**
```
SSH Options: -o Compression=yes -o ServerAliveInterval=60 -o StrictHostKeyChecking=no
```
会自动转换为:
```ssh
Compression yes
ServerAliveInterval 60
StrictHostKeyChecking no
```
### 应用配置
ctty 支持配置文件来自定义行为,包括界面语言、快捷键、自动更新检查以及自定义标签颜色。你也可以直接在 TUI 界面中按 `S` 键打开设置面板进行可视化配置。
**配置文件位置:**
- **Linux/macOS**: `~/.config/ctty/config.json`(遵循 `$XDG_CONFIG_HOME`)
- **Windows**: `%APPDATA%\ctty\config.json`
**示例配置:**
```json
{
"language": "zh_CN",
"check_for_updates": true,
"key_bindings": {
"quit_keys": ["q", "ctrl+c"],
"disable_esc_quit": false
},
"tag_colors": {
"prod": "#FF0055",
"staging": "#FFAA00",
"k8s": "#326CE5",
"mine": "#00DDFF"
}
}
```
**可用选项:**
- **language**: 界面语言,支持 `"auto"`(跟随操作系统语言)、`"zh_CN"`(简体中文)或 `"en"`(English)。默认:`"auto"`。
- **check_for_updates**: 布尔值,启用或禁用启动时的自动更新检查。默认:`true`。在离线机器上设为 `false` 可避免连接延迟。
- **key_bindings.quit_keys**: 退出应用的按键数组。默认:`["q", "ctrl+c"]`
- **key_bindings.disable_esc_quit**: 布尔值,禁用 ESC 键退出应用。默认:`false`。适合 Vim 用户避免误按 ESC 退出。
- **tag_colors**: 标签自定义颜色 Hex 映射字典(如 `{"prod": "#FF0055"}`),优先级高于内置语义色及哈希分配色。
**Vim 用户:**
如果你经常误按 ESC 导致应用退出,将 `disable_esc_quit` 设为 `true`。这会禁用 ESC 作为退出键,同时保留其他所有功能。
**离线机器:**
如果 ctty 因连接 GitHub 时的 DNS 超时而启动缓慢,将 `check_for_updates` 设为 `false`。也可以使用 `--no-update-check` CLI 标志进行一次性覆盖,无需编辑配置文件。
**默认配置:**
如果没有配置文件,ctty 会自动创建一个保持向后兼容的默认配置。
## 🛠️ 开发
### 前置要求
- Go 1.23+
- Git
### 从源码构建
```bash
# 克隆仓库
git clone https://github.com/zsuroy/ctty.git
cd ctty
# 构建二进制
go build -o ctty .
# 运行
./ctty
```
### 项目结构
```
ctty/
├── main.go # 应用入口
├── cmd/ # CLI 命令 (Cobra)
│ ├── root.go # 根命令、CLI 标志与交互模式
│ ├── add.go # 添加主机命令
│ ├── edit.go # 编辑主机命令
│ ├── move.go # 移动主机命令
│ ├── search.go # 搜索命令
│ ├── serial.go # 串口管理命令
│ ├── telnet.go # Telnet 管理 / 直连命令
│ ├── sftp.go # SFTP 文件传输命令
│ ├── ftp.go # FTP 站点管理 / 浏览器命令
│ ├── webdav.go # WebDAV 站点管理 / 浏览器命令
│ ├── info.go # 机器可读 JSON 主机信息
│ └── completion.go # Shell 补全脚本生成
├── internal/
│ ├── config/ # SSH 与应用配置管理
│ │ ├── ssh.go # SSH 配置解析、修改与 Include 展开
│ │ └── appconfig.go# 应用设置 (~/.config/ctty/config.json)
│ ├── connectivity/ # SSH 连通性检查
│ │ └── ping.go # 异步 SSH ping 功能
│ ├── history/ # 连接历史跟踪
│ │ └── history.go # 历史管理和最后登录跟踪
│ ├── i18n/ # 多语言国际化与系统语言探针
│ │ ├── i18n.go # 核心翻译引擎与状态
│ │ ├── locales.go # 中英文双语语言字典
│ │ ├── detect_darwin.go # macOS AppleLocale 系统语言检测
│ │ ├── detect_windows.go # Windows Win32 API 语言检测
│ │ └── detect_other.go # Linux 环境变量与 Android getprop
│ ├── serialconfig/ # 串口设备配置和连接
│ │ ├── serial.go # 设备配置存储 (~/.config/ctty/serial.json)
│ │ ├── ports.go # 端口枚举和辅助函数
│ │ ├── connect.go # 串口连接桥接 (ExecCommand)
│ │ ├── raw_unix.go # POSIX raw 终端模式 (x/term)
│ │ └── raw_windows.go # Windows raw 终端模式 (x/term)
│ ├── rawterm/ # 串口与 telnet 共享的 raw 模式辅助包
│ │ └── rawterm.go # 基于 x/term 的 MakeRaw / Restore 封装
│ ├── telnetconfig/ # Telnet 设备配置
│ │ └── telnet.go # 设备配置存储 (~/.config/ctty/telnet.json,原子写入)
│ ├── telnetclient/ # 原生 RFC 854 telnet 客户端
│ │ └── telnet.go # IAC 状态机、协商与交互桥接
│ ├── sftpconfig/ # SFTP 客户端引擎与文件传输
│ │ └── client.go # SFTP 会话、上传、下载与目录遍历
│ ├── ftpconfig/ # FTP 站点清单 (~/.config/ctty/ftp.json)
│ ├── ftpclient/ # 纯 FTP 传输层(列表、下载、上传、新建、删除、重命名)
│ ├── ftpcred/ # FTP 密码的加密保险库存储(ftp: 前缀)
│ ├── webdavconfig/ # WebDAV 站点清单 (~/.config/ctty/webdav.json)
│ ├── webdavclient/ # WebDAV 传输层(列表、下载、上传、新建、删除、重命名)
│ ├── webdavcred/ # WebDAV 密码的加密保险库存储(webdav: 前缀)
│ ├── version/ # 版本检查和更新
│ │ ├── version.go # GitHub 发布检查和版本比较
│ │ └── version_test.go # 版本解析和比较测试
│ ├── ui/ # 终端 UI 组件 (Bubble Tea)
│ │ ├── tui.go # 主 TUI 界面和程序设置
│ │ ├── model.go # 核心 TUI 模型和状态
│ │ ├── update.go # 消息处理和状态更新
│ │ ├── view.go # UI 渲染和布局
│ │ ├── table.go # 主机列表表格组件、状态指示与 Tag 色彩渲染
│ │ ├── tag_color.go# 语义化与哈希色彩算法
│ │ ├── add_form.go # 添加主机表单界面
│ │ ├── edit_form.go# 编辑主机表单界面
│ │ ├── move_form.go# 移动主机表单界面
│ │ ├── info_form.go# 主机详情弹窗
│ │ ├── help_form.go# 键盘快捷键帮助弹窗
│ │ ├── settings_form.go # 系统设置与偏好配置弹窗
│ │ ├── port_forward_form.go # 端口转发设置和历史
│ │ ├── styles.go # Lip Gloss 样式定义
│ │ ├── sort.go # 排序和过滤逻辑
│ │ ├── serial_form.go # 串口设备列表 UI
│ │ ├── serial_add_form.go # 添加串口设备表单
│ │ ├── serial_connect_form.go # 连接前参数编辑表单
│ │ ├── telnet_form.go # Telnet 设备列表 UI(含可达性探测)
│ │ ├── ftp_sites.go # FTP 站点管理器 UI
│ │ ├── ftp_view.go # FTP 本地|远端双栏浏览器 UI
│ │ ├── webdav_sites.go # WebDAV 站点管理器 UI
│ │ ├── webdav_view.go # WebDAV 双栏文件浏览器 UI
│ │ └── sftp_view.go # SFTP 远程与本地双模文件浏览器
│ └── validation/ # 输入验证
│ └── ssh.go # SSH 配置验证
├── images/ # 文档资源
│ ├── logo.svg # 项目 logo
│ └── ctty.gif # 演示动画
├── install/ # 安装脚本
│ ├── unix.sh # Unix/Linux/macOS 安装器
│ └── README.md # 安装指南
├── .github/ # GitHub 配置
│ ├── copilot-instructions.md # 开发指南
│ └── workflows/ # CI/CD 流水线
│ └── release.yml # GoReleaser 发布
├── go.mod # Go 模块定义
├── go.sum # Go 模块校验
├── .goreleaser.yaml # GoReleaser 配置
├── LICENSE # MIT 许可证
├── CHANGELOG.md # 变更记录
├── README.md # 项目文档(英文)
└── README_CN.md # 项目文档(中文)
```
### 依赖
- [Cobra](https://github.com/spf13/cobra) - CLI 框架
- [Bubble Tea](https://github.com/charmbracelet/bubbletea) - TUI 框架
- [Bubbles](https://github.com/charmbracelet/bubbles) - TUI 组件
- [Lipgloss](https://github.com/charmbracelet/lipgloss) - 样式
- [Go Crypto SSH](https://golang.org/x/crypto/ssh) - SSH 连通性检查
- [go.bug.st/serial](https://github.com/bugst/go-serial) - 跨平台串口通信
## 📦 发布
自动为多平台构建发布版本:
| 平台 | 架构 | 下载 |
|------|------|------|
| Linux | AMD64 | [ctty_Linux_x86_64.tar.gz](https://github.com/zsuroy/ctty/releases/latest/download/ctty_Linux_x86_64.tar.gz) |
| Linux | ARM64 | [ctty_Linux_arm64.tar.gz](https://github.com/zsuroy/ctty/releases/latest/download/ctty_Linux_arm64.tar.gz) |
| macOS | Intel | [ctty_Darwin_x86_64.tar.gz](https://github.com/zsuroy/ctty/releases/latest/download/ctty_Darwin_x86_64.tar.gz) |
| macOS | Apple Silicon | [ctty_Darwin_arm64.tar.gz](https://github.com/zsuroy/ctty/releases/latest/download/ctty_Darwin_arm64.tar.gz) |
| Windows | AMD64 | [ctty_Windows_x86_64.zip](https://github.com/zsuroy/ctty/releases/latest/download/ctty_Windows_x86_64.zip) |
## 🤝 贡献
欢迎贡献!请随时提交 Pull Request。对于重大更改,请先开 issue 讨论你想更改的内容。
### 开发流程
1. **Fork** 仓库
2. **创建** 功能分支(`git checkout -b feature/amazing-feature`)
3. **提交** 你的更改(`git commit -m 'Add amazing feature'`)
4. **推送** 到分支(`git push origin feature/amazing-feature`)
5. **提交** Pull Request
## 📝 许可证
本项目基于 MIT 许可证 —— 详见 [LICENSE](LICENSE) 文件。
## 🙏 致谢
本项目是 [SSHM](https://github.com/Gu1llaum-3/sshm) 的 Fork,由 [@Gu1llaum-3](https://github.com/Gu1llaum-3) 创建。我们感谢使 ctty 成为可能的原始工作。
- [Charm](https://charm.sh/) 提供优秀的 TUI 库
- [Cobra](https://cobra.dev/) 提供出色的 CLI 框架
- [@Gu1llaum-3](https://github.com/Gu1llaum-3) 创建了 sshm,ctty 的 ssh 管理基础
- [@yimeng](https://github.com/yimeng) 贡献 SSH Include 指令支持
- [@ldreux](https://github.com/ldreux) 贡献多词搜索功能
- [@qingfengzxr](https://github.com/qingfengzxr) 贡献自定义快捷键支持
- [Linux.do](https://linux.do) · [V2ex](https://v2ex.com) 开源社区支持
- Go 社区构建了这些出色的工具
## Star History
---
**由 [zsuroy](https://github.com/zsuroy) 用 ❤️ 制作**
⭐ **如果对你有用,请给个 Star!** ⭐