SSH Config Manager
What This Does
A CLI tool to manage SSH configuration files (~/.ssh/config). It helps you organize SSH hosts, generate configurations, test connections, and keep your SSH config clean and maintainable.
Key features:
- - Parse and display existing SSH configs in readable format
- Add/remove/edit hosts in your SSH config
- Organize hosts with tags, groups, or categories
- Test SSH connections to verify hosts work
- Generate configs from templates or JSON/YAML input
- Validate syntax to ensure config files are correct
- Backup and restore your SSH config before making changes
When To Use
- - Your
~/.ssh/config file has become messy with dozens of hosts - You need to quickly test if SSH connections work
- You want to share SSH configs with team members
- You frequently switch between different environments (work/home/cloud)
- You want to organize hosts by project, environment, or team
- You need to validate SSH config syntax before applying changes
Usage
Basic commands:
CODEBLOCK0
Examples
Example 1: List and organize hosts
CODEBLOCK1
Output:
CODEBLOCK2
Example 2: Add a new host with advanced options
CODEBLOCK3
Example 3: Test multiple hosts
CODEBLOCK4
Output:
CODEBLOCK5
Example 4: Generate config from template
CODEBLOCK6
CODEBLOCK7
Requirements
- - Python 3.x
- SSH client installed (
ssh command available in PATH) - Read/write access to
~/.ssh/config (or specified config file)
Limitations
- - This is a CLI tool, not an auto-integration plugin
- Requires Python 3.x and SSH client to be installed
- SSH config syntax validation is basic (doesn't catch all edge cases)
- Connection testing requires SSH keys to be set up properly
- Does not manage SSH keys or certificates
- Limited to standard SSH config options
- Performance depends on number of hosts in config
- Network timeouts can affect connection testing
- Does not support all SSH config advanced features (Match blocks, etc.)
- Backup files use simple timestamp naming
SSH配置管理器
功能说明
这是一个用于管理SSH配置文件(~/.ssh/config)的命令行工具。它可以帮助你整理SSH主机、生成配置、测试连接,并保持SSH配置的整洁和可维护性。
主要功能:
- - 解析并显示 现有SSH配置,以可读格式呈现
- 添加/删除/编辑 SSH配置中的主机
- 使用标签、分组或分类 整理主机
- 测试SSH连接 验证主机是否可用
- 从模板或JSON/YAML输入 生成配置
- 验证语法 确保配置文件正确
- 备份和恢复 修改前的SSH配置
使用场景
- - 你的~/.ssh/config文件因包含数十个主机而变得混乱
- 需要快速测试SSH连接是否正常
- 希望与团队成员共享SSH配置
- 经常在不同环境(工作/家庭/云)之间切换
- 想按项目、环境或团队整理主机
- 需要在应用更改前验证SSH配置语法
使用方法
基本命令:
bash
列出SSH配置中的所有主机
python3 scripts/main.py list
添加新主机
python3 scripts/main.py add --host myserver --hostname 192.168.1.100 --user admin
测试SSH连接到主机
python3 scripts/main.py test --host myserver
按标签整理主机
python3 scripts/main.py organize --tag work --hosts server1,server2,server3
从YAML模板生成SSH配置
python3 scripts/main.py generate --template servers.yaml --output ~/.ssh/config
验证SSH配置语法
python3 scripts/main.py validate --file ~/.ssh/config
示例
示例1:列出并整理主机
bash
python3 scripts/main.py list --format table
输出:
┌─────────────────┬──────────────────────┬───────────┬───────────────┐
│ 主机 │ 主机名 │ 用户 │ 标签 │
├─────────────────┼──────────────────────┼───────────┼───────────────┤
│ github │ github.com │ git │ git │
│ work-server │ 192.168.1.100 │ admin │ work,prod │
│ staging │ staging.example.com │ deploy │ work,staging │
│ personal-vps │ 45.33.22.11 │ root │ personal │
└─────────────────┴──────────────────────┴───────────┴───────────────┘
示例2:添加带高级选项的新主机
bash
python3 scripts/main.py add \
--host new-server \
--hostname server.example.com \
--user ec2-user \
--port 2222 \
--identity ~/.ssh/id_rsa \
--tag aws,production \
--description 生产环境Web服务器
示例3:测试多个主机
bash
python3 scripts/main.py test --hosts work-server,staging,personal-vps
输出:
正在测试SSH连接...
✅ work-server (192.168.1.100): 连接成功
✅ staging (staging.example.com): 连接成功
❌ personal-vps (45.33.22.11): 连接超时
示例4:从模板生成配置
yaml
servers.yaml
hosts:
web-prod:
hostname: web.example.com
user: deploy
port: 22
identityfile: ~/.ssh/deploy_key
tags: [web, production]
db-backup:
hostname: db-backup.internal
user: backup
port: 2222
proxycommand: ssh -W %h:%p bastion
tags: [database, backup]
bash
python3 scripts/main.py generate --template servers.yaml --output ~/.ssh/config
系统要求
- - Python 3.x
- 已安装SSH客户端(ssh命令在PATH中可用)
- 对~/.ssh/config(或指定的配置文件)具有读写权限
限制说明
- - 这是一个命令行工具,不是自动集成插件
- 需要安装Python 3.x和SSH客户端
- SSH配置语法验证为基础级别(无法捕获所有边界情况)
- 连接测试需要正确设置SSH密钥
- 不管理SSH密钥或证书
- 仅限于标准SSH配置选项
- 性能取决于配置中的主机数量
- 网络超时可能影响连接测试
- 不支持所有SSH配置高级功能(如Match块等)
- 备份文件使用简单的时间戳命名