通过 GitHub Actions 在 CI 环境中启动一个临时的 SSH 调试会话,方便在 Workflow 运行过程中进入 Runner 排查问题。
- 🚀 基于 GitHub Actions
- 🔐 支持通过 SSH 进入 GitHub Actions Runner
- 🐛 适合排查 CI/CD 环境中的问题
- 🖥️ 使用
tmate提供交互式终端 - 📦 无需额外部署服务器
进入 GitHub 仓库:
Actions → Interactive Debug → Run workflow
当前 Workflow 使用 workflow_dispatch 触发,因此需要手动执行。
Workflow 会启动一个 Ubuntu Runner,并执行以下步骤:
- Checkout 当前仓库代码
- 安装 Python 3.11
- 启动
tmateSSH 调试会话
对应的 Workflow 文件:
.github/workflows/debug-ssh.yml
Workflow 启动后,tmate 会在日志中输出 SSH 连接信息。
在 GitHub Actions 的 Job 日志中找到类似以下内容:
ssh <user>@<host>
复制 SSH 命令到本地终端即可连接到当前 GitHub Actions Runner。
当前 Workflow 配置:
name: Interactive Debug
on:
workflow_dispatch:
jobs:
debug:
runs-on: ubuntu-latest
steps:
- name: Check Out Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup Tmate SSH Session
uses: mxschmitt/action-tmate@v3
with:
detached: false这个项目主要适合用于 CI/CD 问题排查,例如:
- GitHub Actions 环境与本地环境不一致
- 某个命令在 CI 中运行失败
- 检查环境变量、文件系统或网络状态
- 调试安装依赖的问题
- 排查构建、测试或部署脚本
- 需要直接进入 Runner 查看运行环境
SSH 调试会话可以直接访问当前 GitHub Actions Runner,因此请谨慎使用。
特别注意:
- 不要在公共仓库中泄露敏感信息
- 不要把 SSH 连接信息提交到代码仓库
- 不要在日志中输出 Token、密码或私钥
- 调试完成后及时结束 Workflow
- 建议仅在受信任的仓库和场景中使用
actions-ssh/
├── .github/
│ └── workflows/
│ └── debug-ssh.yml
├── LICENSE
└── README.md
This project is licensed under the MIT License. See the LICENSE file for details.
如果这个项目对你有帮助,欢迎 ⭐ Star。