tunn

strandnerdMIT长期未更新

用一份 YAML 配置和现有的 OpenSSH 环境就能批量启动并监控 SSH 隧道,省去手敲一堆 ssh 命令的麻烦。

SSH tunnels made simple: Launch and monitor SSH tunnels from a single YAML config and your existing OpenSSH setup.

v0.1.1发布于 2025-09-24 02:15 UTC250star11fork同步于 2026-11-07 07:34 UTC

怎么上手

由 README 提炼,执行前请确认
curl -sSL https://raw.githubusercontent.com/strandnerd/tunn/main/scripts/install.sh | sh
go install github.com/strandnerd/tunn@latest
硬件要求按 README 说明

README 未说明;仅要求系统安装 OpenSSH 客户端,支持 macOS 和 Linux,Windows 暂不支持

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用一份 YAML 配置管理多个 SSH 隧道,复用现有 OpenSSH 设置,省去手敲 ssh -L

用一份 YAML 配置和现有的 OpenSSH 环境就能批量启动并监控 SSH 隧道,省去手敲一堆 ssh 命令的麻烦。

核心能力

  • 在单个 YAML 文件中定义全部隧道
  • 按名称选择性启动指定隧道
  • 每条隧道支持多个端口映射
  • 并发启动所有隧道
  • 以守护进程后台运行并通过 IPC 查询状态

容易踩的坑

需先在 ~/.ssh/config 中定义好主机别名,否则 host 字段无法解析;配置文件必须放在 ~/.tunnrc;守护进程运行文件写入 $XDG_RUNTIME_DIR/tunn,该目录不可用时回退到 ~/.cache/tunn

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

2 个版本v0.1.1
  1. v0.1.1最新正式版2025-09-24 · 2025-09-24 02:15 UTC
  2. v0.1.02025-09-24 · 2025-09-24 01:10 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/strandnerd/tunn/commits/v0.1.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    GitHub License GitHub Actions Workflow Status GitHub Release GitHub Issues or Pull Requests

    tunn - SSH Tunnel Manager

    tunn is a developer-friendly wrapper around OpenSSH that makes it easy to manage multiple SSH tunnels defined in a simple configuration file

    Features

    • 🚀 Simple Configuration: Define all your tunnels in a single YAML file
    • 🔧 Selective Tunnels: Run all tunnels or specific ones by name
    • 🔌 Multiple Ports: Support for multiple port mappings per tunnel
    • 🔐 SSH Integration: Leverages your existing SSH configuration
    • ⚡ Parallel Execution: All tunnels run concurrently
    • 🧩 Daemon Mode: Background service with status reporting via IPC
    • 🧼 Lean Go Module: Depends only on gopkg.in/yaml.v3, keeping builds clean and portable
    • 🔧 Native SSH Sessions: Spawns the system ssh binary for each mapping, so keys and config behave exactly like your shell
    • 🎚️ Per-Port Processes: Launches one PID per port to pave the way for fine-grained lifecycle controls

    Screencast from 2025-09-23 22-19-13 (online-video-cutter com)

    Installation

    Quick Install

    curl -sSL https://raw.githubusercontent.com/strandnerd/tunn/main/scripts/install.sh | sh
    

    From Go Install

    go install github.com/strandnerd/tunn@latest
    

    Build Locally

    git clone https://github.com/strandnerd/tunn.git
    cd tunn
    go build -o tunn
    sudo mv tunn /usr/local/bin/
    

    Configuration

    Create a ~/.tunnrc file in your home directory:

    tunnels:
      api:
        host: myserver          # SSH host from ~/.ssh/config
        ports:
          - 3000:3000           # local:remote port mapping
          - 4000:4001
        user: apiuser           # optional: SSH user
        identity_file: ~/.ssh/id_rsa  # optional: SSH key
    
      db:
        host: database
        ports:
          - 3306:3306           # MySQL
          - 5432:5432           # PostgreSQL
        user: dbadmin           # optional: overrides SSH config
    
      cache:
        host: cacheserver
        ports:
          - 6379:6379           # Redis
    

    Configuration Fields

    • tunnels: Map of tunnel names
    • host: SSH host alias from ~/.ssh/config
    • ports: List of port mappings in local:remote format
    • user (optional): SSH username (overrides ~/.ssh/config)
    • identity_file (optional): Path to SSH private key

    Usage

    Run All Tunnels

    tunn
    

    Run Specific Tunnels

    # Single tunnel
    tunn api
    
    # Multiple tunnels
    tunn api db
    
    # All database-related tunnels
    tunn db cache
    

    Run Tunnels in the Background

    tunn --detach
    
    # Or only specific tunnels
    tunn --detach api db
    

    The CLI respawns itself as a daemon, stores metadata under $XDG_RUNTIME_DIR/tunn (or ~/.cache/tunn when the runtime dir is unavailable), and immediately returns control to the terminal.

    Check Daemon Status

    tunn status
    

    The status command contacts the daemon's Unix socket, reporting the PID, mode, and the latest port states for each managed tunnel. If no daemon is running, a friendly message is printed instead.

    Stop the Daemon

    tunn stop
    

    The stop command asks the daemon to shut down cleanly, waits for it to exit, and reports success.

    Output Example

    Tunnels Ready
    
    [api]
        3000 ➜ 3000 [active]
        4000 ➜ 4001 [active]
    [db]
        3306 ➜ 3306 [connecting]
        5432 ➜ 5432 [active]
    

    SSH Configuration

    tunn uses your system's SSH configuration. Make sure your hosts are defined in ~/.ssh/config:

    Host myserver
        HostName 192.168.1.100
        User myuser
        Port 22
    
    Host database
        HostName db.example.com
        User dbuser
        IdentityFile ~/.ssh/db_key
    

    Requirements

    • Go 1.21 or higher (for building)
    • OpenSSH client (ssh command)
    • Valid SSH configuration
    • macOS and Linux are supported today; Windows support is planned but not available yet

    Daemon Runtime Files

    While running in detached mode, tunn stores the following files in its runtime directory:

    • daemon.pid – PID of the active daemon; used to prevent duplicate launches.
    • daemon.sock – Unix domain socket for control commands (e.g., tunn status).
    • daemon.log – Aggregated stdout/stderr from the daemon process.

    The directory is created with 0700 permissions, and files are cleaned up automatically when the daemon exits or when stale state is detected on the next launch.