ssh
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSSH Skill
SSH Skill
定位
Overview
这是一个轻量 SSH 操作网关。它不维护独立服务器数据库,默认只读取和写入标准 OpenSSH 配置:
text
~/.ssh/config核心原则:
- 使用 别名标识服务器,不直接记忆 IP/密码。
Host - 优先密钥认证和 OpenSSH 原生命令。
- 通过本 skill 的 脚本执行 SSH、SCP、配置检查和隧道操作。
scripts/ - 写入 前必须自动备份。
~/.ssh/config - 不鼓励密码落盘;如必须使用密码,优先让 OpenSSH 交互提示或由用户自行配置安全凭据。
This is a lightweight SSH operation gateway. It does not maintain an independent server database and only reads and writes the standard OpenSSH configuration by default:
text
~/.ssh/configCore Principles:
- Use aliases to identify servers, do not directly memorize IPs/passwords.
Host - Prioritize key authentication and native OpenSSH commands.
- Execute SSH, SCP, configuration checks, and tunnel operations through the scripts of this skill.
scripts/ - Automatic backup is required before writing to .
~/.ssh/config - Storing passwords locally is discouraged; if passwords must be used, prioritize letting OpenSSH prompt interactively or having users configure secure credentials on their own.
何时触发
Trigger Scenarios
当用户提到以下任务时使用本 skill:
- SSH、远程服务器、服务器 IP/主机名、
user@host - 登录、执行远程命令、检查服务器状态
- 上传、下载、部署、迁移文件
- 跳板机、、内网访问
ProxyJump - 隧道、端口转发、数据库连接
- 配置 、新增/查找服务器别名
~/.ssh/config
不要用于本机 、当前目录、本地文件操作或普通网络概念解释。
localhostUse this skill when users mention the following tasks:
- SSH, remote servers, server IP/hostname,
user@host - Login, execute remote commands, check server status
- Upload, download, deploy, migrate files
- Bastion host, , intranet access
ProxyJump - Tunnel, port forwarding, database connection
- Configure , add/search server aliases
~/.ssh/config
Do not use for local , current directory, local file operations, or general network concept explanations.
localhost脚本入口
Script Entry
优先从当前 skill 目录调用脚本。脚本目录为:
text
scripts/命令示例均以当前 skill 目录为基准。
Prioritize calling scripts from the current skill directory. The script directory is:
text
scripts/Command examples are all based on the current skill directory.
常用命令
Common Commands
ssh_exec.pyssh_transfer.pyssh_tunnel.pybash
--accept-new-host-key
--known-hosts-file <临时known_hosts路径>首次连接已确认可信的新开发板时,可显式追加 。测试时如不想写入全局 ,可追加 。
--accept-new-host-keyknown_hosts--known-hosts-file <临时known_hosts路径>ssh_exec.pyssh_transfer.pyssh_tunnel.pybash
--accept-new-host-key
--known-hosts-file <temporary known_hosts path>When connecting to a trusted new development board for the first time, you can explicitly append . If you don't want to write to the global during testing, you can append .
--accept-new-host-keyknown_hosts--known-hosts-file <temporary known_hosts path>列出服务器
List Servers
bash
python scripts/ssh_config.py listbash
python scripts/ssh_config.py list查找服务器
Search for Servers
bash
python scripts/ssh_config.py find <关键词>bash
python scripts/ssh_config.py find <keyword>验证别名解析
Verify Alias Resolution
bash
python scripts/ssh_config.py show <别名>bash
python scripts/ssh_config.py show <alias>新增服务器
Add Server
写入前脚本会自动备份 :
~/.ssh/configbash
python scripts/ssh_config.py add <别名> --host <IP或域名> --user <用户> --port 22 --key ~/.ssh/id_ed25519可选:
bash
--description "说明"
--tags tag1,tag2
--location "位置"
--proxy-jump <跳板机别名>The script will automatically back up before writing:
~/.ssh/configbash
python scripts/ssh_config.py add <alias> --host <IP or domain> --user <user> --port 22 --key ~/.ssh/id_ed25519Optional:
bash
--description "Description"
--tags tag1,tag2
--location "Location"
--proxy-jump <bastion host alias>执行远程命令
Execute Remote Command
bash
python scripts/ssh_exec.py <别名> "命令" --timeout 30脚本输出 JSON,包含 、、、。
successexit_codestdoutstderrbash
python scripts/ssh_exec.py <alias> "command" --timeout 30The script outputs JSON, including , , , .
successexit_codestdoutstderr上传文件
Upload Files
bash
python scripts/ssh_transfer.py upload <别名> "<本地路径>" "<远程路径>"bash
python scripts/ssh_transfer.py upload <alias> "<local path>" "<remote path>"下载文件
Download Files
bash
python scripts/ssh_transfer.py download <别名> "<远程路径>" "<本地路径>"bash
python scripts/ssh_transfer.py download <alias> "<remote path>" "<local path>"建立本地端口转发
Establish Local Port Forwarding
bash
python scripts/ssh_tunnel.py <别名> --local-port <本地端口> --remote-host 127.0.0.1 --remote-port <远程端口>隧道命令会前台运行。需要后台长期保持时,先向用户说明影响和停止方式。
bash
python scripts/ssh_tunnel.py <alias> --local-port <local port> --remote-host 127.0.0.1 --remote-port <remote port>The tunnel command runs in the foreground. If long-term background operation is needed, explain the impact and stop method to the user first.
配置格式
Configuration Format
推荐配置:
ssh
undefinedRecommended Configuration:
ssh
undefineddescription: 开发板
description: Development Board
tags: embedded,linux
tags: embedded,linux
location: lab
location: lab
Host 1380-P904
HostName 192.168.137.76
User root
Port 22
IdentityFile ~/.ssh/id_ed25519
跳板机:
```ssh-config
Host bastion
HostName bastion.example.com
User root
IdentityFile ~/.ssh/id_ed25519
Host internal-dev
HostName 10.0.1.20
User root
IdentityFile ~/.ssh/id_ed25519
ProxyJump bastion允许保留注释元数据:
descriptiontagslocation
不要在配置中写入真实密码、Token、私钥内容或其他敏感信息。
Host 1380-P904
HostName 192.168.137.76
User root
Port 22
IdentityFile ~/.ssh/id_ed25519
Bastion Host:
```ssh-config
Host bastion
HostName bastion.example.com
User root
IdentityFile ~/.ssh/id_ed25519
Host internal-dev
HostName 10.0.1.20
User root
IdentityFile ~/.ssh/id_ed25519
ProxyJump bastionComment metadata is allowed to be retained:
descriptiontagslocation
Do not write real passwords, Tokens, private key contents, or other sensitive information in the configuration.
操作规则
Operation Rules
- 查询类任务可以直接执行。
- 新增或修改 前,脚本必须创建备份。
~/.ssh/config - 删除配置、覆盖远程文件、部署、批量执行、端口转发等有风险操作,先向用户确认。
- 不直接运行裸 /
ssh,优先使用本 skill 的脚本;只有在脚本不可用或用户明确请求时,才说明原因并使用回退命令。scp - 不修改 Git、系统服务、防火墙、远程生产环境配置,除非用户明确要求。
- 执行远程命令时优先只读检查;涉及重启、删除、覆盖、安装、升级时先确认。
- 输出给用户时说明目标别名、实际 HostName、执行命令、关键结果和失败原因。
- Query tasks can be executed directly.
- The script must create a backup before adding or modifying .
~/.ssh/config - For risky operations such as deleting configurations, overwriting remote files, deployment, batch execution, port forwarding, confirm with the user first.
- Do not directly run bare /
ssh; prioritize using the scripts of this skill; only explain the reason and use fallback commands when the scripts are unavailable or explicitly requested by the user.scp - Do not modify Git, system services, firewalls, or remote production environment configurations unless explicitly requested by the user.
- Prioritize read-only checks when executing remote commands; confirm first when involving restart, deletion, overwriting, installation, or upgrade.
- When outputting to the user, explain the target alias, actual HostName, executed command, key results, and failure reasons.
故障排查
Troubleshooting
优先检查:
python scripts/ssh_config.py show <别名>- 是否能解析 HostName/User/Port
ssh -G <别名> - 密钥文件是否存在,权限是否合适
- 别名是否也在
ProxyJump~/.ssh/config - 网络是否可达,端口是否开放
- 首次连接是否需要显式追加
--accept-new-host-key
如果脚本失败,保留真实 stderr,不要吞掉错误。
Prioritize checking:
python scripts/ssh_config.py show <alias>- Whether can resolve HostName/User/Port
ssh -G <alias> - Whether the key file exists and has appropriate permissions
- Whether the alias is also in
ProxyJump~/.ssh/config - Whether the network is reachable and the port is open
- Whether needs to be explicitly appended for the first connection
--accept-new-host-key
If the script fails, retain the actual stderr and do not suppress errors.