improve linux-ssh-operator-skill: bug fixes, rsync support, tunneling docs
- Fix dry-run bug in ssh_alias_setup.sh (pub key check skipped when key was never generated) - Remove dead code in ssh_run.sh (-- check after host arg was never reachable) - Add --rsync/--delete flags to ssh_copy.sh for incremental rsync transfers - Add -C/--compress flag to ssh_run.sh for slow-link connections - Expand SKILL.md/SKILL.zh-CN.md: tunneling, jump host, SSH multiplexing, Docker ops - Expand ssh-playbook.md: port forwarding, bastion, ControlMaster, structured troubleshooting table Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
---
|
||||
name: linux-ssh-operator-skill
|
||||
description: 通过 SSH 连接并操作 Linux 服务器:执行远程命令、查看日志、管理 systemd 服务、传输文件(scp/rsync)、配置 SSH 别名、安装公钥启用免密登录、排障。用户提到 ssh/scp/rsync、远程服务器 IP:端口、配置 ssh 别名、ssh-copy-id、免密登录、systemctl/journalctl、部署到服务器、在服务器上运行命令、远程拷贝文件 等场景时使用。
|
||||
description: 通过 SSH 连接并操作 Linux 服务器:执行远程命令、查看日志、管理 systemd 服务、传输文件(scp/rsync)、配置 SSH 别名、安装公钥启用免密登录、SSH 隧道/端口转发、跳板机、内网穿透、排障。用户提到 ssh/scp/rsync、远程服务器 IP:端口、配置 ssh 别名、ssh-copy-id、免密登录、systemctl/journalctl、部署到服务器、在服务器上运行命令、远程拷贝文件、SSH 隧道、端口转发、跳板机、堡垒机、服务器上看一下、帮我连上服务器、查看服务器日志 等场景时使用。
|
||||
|
||||
---
|
||||
|
||||
# Linux SSH Operator
|
||||
|
||||
## Overview
|
||||
|
||||
Use SSH to connect to Linux servers and perform safe, repeatable remote operations (commands, logs, services, file transfer, alias bootstrap, passwordless login).
|
||||
Use SSH to connect to Linux servers and perform safe, repeatable remote operations (commands, logs, services, file transfer, alias bootstrap, passwordless login, tunnels).
|
||||
|
||||
## Workflow
|
||||
|
||||
@@ -99,29 +100,85 @@ ssh -tt my-server sudo systemctl status nginx --no-pager
|
||||
```bash
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_run.sh my-server -- uname -a
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_run.sh --tty --sudo my-server -- systemctl restart nginx
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_run.sh --compress my-server -- cat /var/log/big.log
|
||||
```
|
||||
|
||||
### Transfer files
|
||||
|
||||
Upload:
|
||||
Upload (scp):
|
||||
|
||||
```bash
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_copy.sh push my-server ./local.txt /tmp/local.txt
|
||||
```
|
||||
|
||||
Download:
|
||||
Download (scp):
|
||||
|
||||
```bash
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_copy.sh pull my-server /var/log/syslog ./syslog
|
||||
```
|
||||
|
||||
Incremental sync (rsync — preferred for directories or large files):
|
||||
|
||||
```bash
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_copy.sh --rsync push my-server ./dist/ /var/www/html/
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_copy.sh --rsync --delete push my-server ./dist/ /var/www/html/
|
||||
~/.claude/skills/linux-ssh-operator-skill/scripts/ssh_copy.sh --rsync pull my-server /var/log/ ./logs/
|
||||
```
|
||||
|
||||
### SSH Tunneling / Port Forwarding
|
||||
|
||||
Local forward (access remote service on a local port):
|
||||
|
||||
```bash
|
||||
# Access remote MySQL (3306) at localhost:13306
|
||||
ssh -L 13306:127.0.0.1:3306 my-server -N
|
||||
```
|
||||
|
||||
Remote forward (expose a local port on the server):
|
||||
|
||||
```bash
|
||||
# Make local :8080 accessible on server's :18080
|
||||
ssh -R 18080:127.0.0.1:8080 my-server -N
|
||||
```
|
||||
|
||||
Jump host (bastion → target):
|
||||
|
||||
```bash
|
||||
ssh -J bastion-user@bastion:22 target-user@target-host
|
||||
```
|
||||
|
||||
Or configure in `~/.ssh/config`:
|
||||
|
||||
```sshconfig
|
||||
Host target-internal
|
||||
HostName 10.0.0.50
|
||||
User ubuntu
|
||||
ProxyJump bastion
|
||||
```
|
||||
|
||||
### SSH Multiplexing (faster repeated connections)
|
||||
|
||||
Add to `~/.ssh/config` to reuse the same TCP connection:
|
||||
|
||||
```sshconfig
|
||||
Host *
|
||||
ControlMaster auto
|
||||
ControlPath ~/.ssh/ctrl-%h-%p-%r
|
||||
ControlPersist 60s
|
||||
```
|
||||
|
||||
The first `ssh my-server` opens a master connection; subsequent connections reuse it without re-handshaking.
|
||||
|
||||
## Common Ops (snippets)
|
||||
|
||||
- Disk: `df -h`, `du -sh /path/* | sort -h`
|
||||
- Memory/CPU: `free -h`, `top`, `ps aux --sort=-%mem | head`
|
||||
- Logs: `journalctl -u SERVICE -n 200 --no-pager`, `tail -n 200 -f /path/log`
|
||||
- Services: `systemctl status|restart|stop SERVICE`
|
||||
- Services: `systemctl status|restart|stop|enable SERVICE`
|
||||
- Networking: `ss -lntp`, `ip a`, `ip r`, `curl -v http://127.0.0.1:PORT/`
|
||||
- Docker: `docker ps`, `docker logs -f CONTAINER`, `docker exec -it CONTAINER bash`
|
||||
- Config test: `nginx -t`, `sshd -T`
|
||||
- Open files: `lsof -i :PORT`, `fuser PORT/tcp`
|
||||
|
||||
## Safety
|
||||
|
||||
@@ -136,5 +193,5 @@ Download:
|
||||
## Scripts
|
||||
|
||||
- `scripts/ssh_alias_setup.sh`: create/update SSH aliases and optionally run `ssh-copy-id`.
|
||||
- `scripts/ssh_run.sh`: run remote commands with consistent options.
|
||||
- `scripts/ssh_copy.sh`: push/pull files via scp with consistent options.
|
||||
- `scripts/ssh_run.sh`: run remote commands with consistent options (supports `--compress`, `--tty`, `--sudo`).
|
||||
- `scripts/ssh_copy.sh`: push/pull files via scp or rsync (use `--rsync` for incremental transfers).
|
||||
|
||||
Reference in New Issue
Block a user