autosshを手軽にする
  • Shell 68.7%
  • Go 27.3%
  • Python 4%
Find a file
Ubuntu 17d8b33ac3 fix: SSH接続安定性とエラーメッセージを改善
- generate_ssh_config() に GSSAPIAuthentication yes を追加
  (-F 使用時にシステム設定が欠落する問題の対策)
- SSHエラー検出パターンに Connection reset by peer 等を追加
  (Exceeded MaxStartups による接続断を早期検知)
- プロセス終了時のエラーメッセージを改善
  (「ポートチェック失敗」から実際のSSHログ表示に変更)
2026-07-18 20:31:54 +09:00
.planning docs: map existing codebase for autosshx project initialization 2026-07-01 17:02:56 +09:00
archive
autosshx_new
bin
docs
tests fix: test_ipv6.shのIPv6対応テストを修正 2026-07-17 14:47:26 +09:00
.gitignore chore: .worktrees/ディレクトリをgitignoreに追加 2026-06-21 05:57:51 +09:00
AGENTS.md
autosshx fix: SSH接続安定性とエラーメッセージを改善 2026-07-18 20:31:54 +09:00
autosshx.backup
autosshx.exe
CHECKPOINT.md docs: TODO.md と CHECKPOINT.md を更新(Go再実装版設計書・テスト追加セッション) 2026-05-13 22:21:01 +09:00
DESIGN.md docs: バージョン表記を更新 2026-07-17 14:52:12 +09:00
PROGRESS.md
README.md docs: バージョン表記を更新 2026-07-17 14:52:12 +09:00
REVIEW.md docs: autosshxバグ監査レポートを追加 2026-06-21 04:56:33 +09:00
TODO.md docs: mark codebase mapping as completed in TODO 2026-07-01 17:03:46 +09:00

autosshx v2.1.2

SSH Port Forwarding Management Tool

概要

autosshx is an SSH port forwarding management tool. It provides session management, auto-recovery, and protect features, allowing you to manage SSH tunnels with simple commands.

autosshx は SSH ポートフォワーディングの管理ツールです。 セッション管理、自動復旧、プロテクト機能などを備え、簡単なコマンドで SSH トンネルを管理できます。

主な機能

  • セッション管理: 各トンネルをシリアル番号で管理
  • 自動復旧: ウォッチャープロセスで監視、停止時に自動再起動
  • プロテクト機能: 重要なトンネルを削除から保護
  • HTTP/HTTPS 自動判定: ターゲットのサービス種別を自動検出し URL を表示
  • -u オプション: URL 表示を抑制(デフォルト:表示)
  • 疎通テスト: ポートフォワーディングの接続状態を確認
  • 多言語対応: 日本語/中国語/ヒンディー語/ロシア語/英語LANG環境変数に依存
  • 一時SSH config: SSH config の競合を回避する一時設定ファイル生成
  • カラー表示: 視覚的な状態表示(無効化可能)

IPv6対応

autosshxはIPv6アドレスをサポートしています。

使用例

# bracket付きIPv6アドレスでトンネル作成
./autosshx -L 8080:[2001:db8::1]:80@remote.example.com

# リバーストンネルIPv6アドレス
./autosshx -R 8080:[2001:db8::1]:80@remote.example.com

注意事項

  • IPv6アドレスはbracket[])で囲んで指定してください
  • ポート番号はIPv6アドレスの後にコロンで区切って指定してください

インストール (Installation)

# リポジトリをクローン
git clone <repository-url>
cd autosshx

# 実行権限を付与
install -m755 ./autosshx /usr/local/bin/

# または
chmod +x autosshx
sudo cp autosshx /usr/local/bin/

これで autosshx コマンドがシステム全体から利用可能になります。

使用方法 (Usage)

基本的なコマンド (Basic Commands)

# セッション一覧表示 (List sessions)
./autosshx

# トンネル追加 - ローカルフォワード (Add tunnel - local forward)

# @形式(従来の方法): LPORT:RPORT@RHOST RHOST上のポートへ転送
./autosshx -L 8080:80@remote.example.com

# @形式: LPORT:DEST:RPORT@RHOST RHOST経由でDEST:RPORTへ転送
./autosshx -L 8080:192.168.1.1:80@remote.example.com

# 既存互換形式: LPORT:RHOST:RPORT RHOST上のポートへ転送
./autosshx -L 2222:remote.example.com:22
# カンマ区切りで複数指定も可能HOST LPORT:RHOST:RPORT,LPORT2:RHOST2:RPORT2
./autosshx ai2 38082:ai2:8080,38085:ai5:8080

# スペースなし形式
./autosshx -L8080:80@remote.example.com

# カンマ区切り(新機能): 1つのホストに複数のポートをまとめて指定
./autosshx -L ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080

# bare 引数 + カンマ区切り(新機能): ホスト名を先頭に指定、カンマで複数ポート定義
./autosshx ai2 48082:11430,48085:ai5:8080

### トンネル定義形式詳細 (Tunnel Definition Formats)

**推奨形式bare 引数 + カンマ区切り):**
```bash
# RHOST へのローカルフォワード
./autosshx ai2 8080:80@remote.example.com

# RHOST 経由で別のホストへ転送
./autosshx ai2 8080:192.168.1.1:80@remote.example.com

# カンマ区切りで複数のポート定義をまとめて指定(推奨)
./autosshx ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080

# リバーストンネル
./autosshx ai2 8080:80@remote.example.com

既存互換形式(レガシー):

# LPORT:RHOST:RPORT RHOST 上のポートへ転送)
./autosshx -L 2222:remote.example.com:22

# カンマ区切り複数指定(ホスト名を先頭)
./autosshx ai2 38082:ai2:8080,38085:ai5:8080

@形式(従来の方法):

# RHOST 上のポートへ転送
./autosshx -L 8080:80@remote.example.com

# RHOST 経由で別のホストへ転送
./autosshx -L 8080:192.168.1.1:80@remote.example.com

スペースなし形式:

./autosshx -L8080:80@remote.example.com

リバーストンネル (Reverse tunnel)

./autosshx -R 8080:80@remote.example.com ./autosshx -R 8080:192.168.1.1:80@remote.example.com

カンマ区切りリバーストンネル(新機能)

./autosshx -R ai2 48082:11430,48085:ai5:8080

トンネル削除(シリアル番号指定)

./autosshx -d 1

全トンネルを削除(プロテクトされているものは除く)

./autosshx -R

トンネルの疎通テスト

./autosshx -t

特定シリアルの疎通テスト

./autosshx -t 1

ヘルプ表示

./autosshx -h


### オプション一覧 (Options)

| オプション | 説明 | 例 |
|------------|------|-----|
| (none) | List sessions | `./autosshx` |
| `-L LPORT:RPORT@RHOST` | Local forward | `./autosshx -L 8080:80@host` |
| `-L LPORT:DEST:RPORT@RHOST` | Local forward (via RHOST) | `./autosshx -L 8080:192.168.1.1:80@host` |
| `-L LPORT:RHOST:RPORT` | Local forward (legacy) | `./autosshx -L 2222:host:22` |
| `-L HOST PORTS` | Local forward (カンマ区切り複数ポート) | `./autosshx -L host 8080:80,8081:81` |
| `-R LPORT:RPORT@RHOST` | Reverse tunnel | `./autosshx -R 8080:80@host` |
| `-R LPORT:DEST:RPORT@RHOST` | Reverse tunnel (via RHOST) | `./autosshx -R 8080:192.168.1.1:80@host` |
| `-R HOST PORTS` | Reverse tunnel (カンマ区切り複数ポート) | `./autosshx -R host 8080:80,8081:81` |
| `-R` | Delete all tunnels (except protected) | `./autosshx -R` |
| `-d SERIAL` | Delete tunnel | `./autosshx -d 1` |
| `-P SERIAL` | Protect tunnel | `./autosshx -P 1` |
| `-U SERIAL` | Unprotect tunnel | `./autosshx -U 1` |
| `-U` | Unprotect all tunnels | `./autosshx -U` |
| `-t` | Test all tunnels | `./autosshx -t` |
| `-t SERIAL` | Test specific tunnel | `./autosshx -t 1` |
| `--stop` | Stop all tunnels | `./autosshx --stop` |
| `-f` | Force overwrite (port in use) | `./autosshx -f -L 8080:80@host` |
| `-q` | Quiet mode | `./autosshx -q` |
| `--color` | Enable color (default) | `./autosshx --color` |
| `--no-color` | Disable color | `./autosshx --no-color` |
| `-h, --help` | Show help | `./autosshx -h` |

## 使用例 (Examples)

### SSH ポートフォワーディング (SSH Port Forwarding)

```bash
# リモートサーバの SSH ポートにローカルポート 2222 でフォワード
./autosshx -L 2222:22@remote.example.com

# Web サーバのポート 80 をローカルポート 8080 でフォワード
./autosshx -L 8080:80@web.example.com

# リモートサーバ経由で別ホストのポートへフォワード
./autosshx -L 3306:192.168.1.100:3306@gateway.example.com

# カンマ区切りで複数のポートをまとめて指定(新機能)
./autosshx -L ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080

# bare引数でホスト名を指定 + カンマ区切り(新機能)
./autosshx ai2 48082:11430,48085:ai5:8080

リバーストンネル (Reverse Tunnel)

# ローカルポート 8080 をリモートサーバ上で公開
./autosshx -R 8080:80@remote.example.com

# ローカルの開発サーバをリモートからアクセス可能に
./autosshx -R 3000:3000@remote.example.com

プロテクト機能 (Protect Feature)

# 重要なトンネルをプロテクト
./autosshx -P 1

# プロテクトを解除
./autosshx -U 1

# 全プロテクトを解除
./autosshx -U

テストと監視 (Test and Monitoring)

# 全トンネルの疎通テスト
./autosshx -t

# 特定のトンネルをテスト
./autosshx -t 1

# 全トンネルを停止
./autosshx --stop

ファイル構成 (File Structure)

/home/user/autosshx/
├── autosshx          # Main script
├── archive/          # Old version archives
├── tests/            # Test scripts
├── logs/             # Log directory (created on demand)
├── README.md         # This file
├── DESIGN.md         # Design documentation
└── AGENTS.md         # Agent guide

一時ファイル (Temporary Files)

セッション管理は ~/.local/share/autosshx/ ディレクトリに以下のファイルを使用します:

Session management uses the following files in ~/.local/share/autosshx/:

~/.local/share/autosshx/
├── README.md           # このディレクトリの説明
├── sessions/           # セッション情報
│   ├── 1/              # シリアル番号 1
│   │   ├── pid         # プロセス ID
│   │   ├── remote      # リモートホスト
│   │   ├── forwards    # フォワーディング設定
│   │   └── ssh_config  # 一時 SSH 設定ファイル
│   ├── 2/              # シリアル番号 2
│   └── ...
├── protect             # プロテクトされたシリアル番号
├── watcher.pid         # ウォッチャーの PID
└── logs/               # ログファイル

XDG_DATA_HOME 環境変数を設定することで、ベースディレクトリを変更できます:

export XDG_DATA_HOME=/custom/path
# → /custom/path/autosshx/sessions/

環境変数 (Environment Variables)

変数名 説明 デフォルト
LANG Language setting (ja/zh/hi/ru/en) System default
XDG_DATA_HOME Base directory for session data ~/.local/share
AUTOSSHX_COLOR Enable/disable color output (false to disable) true

セキュリティ (Security)

  • 一時 SSH 設定ファイルは chmod 600 で作成されます
  • プロセス識別のため UUID が使用されます
  • ログファイルは ~/.local/share/autosshx/logs/ に保存されます

トラブルシューティング

トンネルが接続できない

  1. リモートホストとポートの確認
  2. SSH キーまたはパスワード認証の確認
  3. ファイアウォール設定の確認
  4. ログの確認: ~/.local/share/autosshx/logs/autosshx.log

ウォッチャーが動作しない

  1. ウォッチャーの PID ファイル確認: cat ~/.local/share/autosshx/watcher.pid
  2. プロセスの生存確認: ps -p <PID>
  3. ログの確認: ~/.local/share/autosshx/logs/autosshx.log

開発

テスト

# 構文チェック
bash -n autosshx

# テスト実行(如果有り)
cd tests
./test_all.sh

コントリビューション

  1. このリポジトリをフォーク
  2. 機能ブランチを作成: git checkout -b feature/my-feature
  3. 変更をコミット: git commit -m 'feat: 機能の追加'
  4. ブランチをプッシュ: git push origin feature/my-feature
  5. プルリクエストを作成

ライセンス

MIT ライセンス(またはプロジェクトのライセンス)

作者

krasherjoe

バージョン

  • 現在: v2.1.2
  • 最終更新: 2026-07-17