No description
- Shell 100%
| docs | ||
| tests | ||
| .gitignore | ||
| AGENTS.md | ||
| build.sh | ||
| DESIGN.md | ||
| README.md | ||
| REVIEW.md | ||
| ssj | ||
| TODO.md | ||
ssj v2.1.2
SSH Port Forwarding Management Tool
概要
ssj 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.
ssj は SSH ポートフォワーディングの管理ツールです。 セッション管理、自動復旧、プロテクト機能などを備え、簡単なコマンドで SSH トンネルを管理できます。
主な機能
- セッション管理: 各トンネルをシリアル番号で管理
- 自動復旧: ウォッチャープロセスで監視、停止時に自動再起動
- プロテクト機能: 重要なトンネルを削除から保護
- HTTP/HTTPS 自動判定: ターゲットのサービス種別を自動検出し URL を表示
-uオプション: URL 表示を抑制(デフォルト:表示)- 疎通テスト: ポートフォワーディングの接続状態を確認
- 多言語対応: 日本語/中国語/ヒンディー語/ロシア語/英語(LANG環境変数に依存)
- 一時SSH config: SSH config の競合を回避する一時設定ファイル生成
- カラー表示: 視覚的な状態表示(無効化可能)
IPv6対応
ssjはIPv6アドレスをサポートしています。
使用例
# bracket付きIPv6アドレスでトンネル作成
./ssj -L 8080:[2001:db8::1]:80@remote.example.com
# リバーストンネル(IPv6アドレス)
./ssj -R 8080:[2001:db8::1]:80@remote.example.com
注意事項
- IPv6アドレスはbracket(
[])で囲んで指定してください - ポート番号はIPv6アドレスの後にコロンで区切って指定してください
インストール (Installation)
# リポジトリをクローン
git clone <repository-url>
cd ssj
# 実行権限を付与
install -m755 ./ssj /usr/local/bin/
# または
chmod +x ssj
sudo cp ssj /usr/local/bin/
これで ssj コマンドがシステム全体から利用可能になります。
使用方法 (Usage)
基本的なコマンド (Basic Commands)
# セッション一覧表示 (List sessions)
./ssj
# トンネル追加 - ローカルフォワード (Add tunnel - local forward)
# @形式(従来の方法): LPORT:RPORT@RHOST (RHOST上のポートへ転送)
./ssj -L 8080:80@remote.example.com
# @形式: LPORT:DEST:RPORT@RHOST (RHOST経由でDEST:RPORTへ転送)
./ssj -L 8080:192.168.1.1:80@remote.example.com
# 既存互換形式: LPORT:RHOST:RPORT (RHOST上のポートへ転送)
./ssj -L 2222:remote.example.com:22
# カンマ区切りで複数指定も可能:HOST LPORT:RHOST:RPORT,LPORT2:RHOST2:RPORT2
./ssj ai2 38082:ai2:8080,38085:ai5:8080
# スペースなし形式
./ssj -L8080:80@remote.example.com
# カンマ区切り(新機能): 1つのホストに複数のポートをまとめて指定
./ssj -L ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080
# bare 引数 + カンマ区切り(新機能): ホスト名を先頭に指定、カンマで複数ポート定義
./ssj ai2 48082:11430,48085:ai5:8080
### トンネル定義形式詳細 (Tunnel Definition Formats)
**推奨形式(bare 引数 + カンマ区切り):**
```bash
# RHOST へのローカルフォワード
./ssj ai2 8080:80@remote.example.com
# RHOST 経由で別のホストへ転送
./ssj ai2 8080:192.168.1.1:80@remote.example.com
# カンマ区切りで複数のポート定義をまとめて指定(推奨)
./ssj ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080
# リバーストンネル
./ssj ai2 8080:80@remote.example.com
既存互換形式(レガシー):
# LPORT:RHOST:RPORT (RHOST 上のポートへ転送)
./ssj -L 2222:remote.example.com:22
# カンマ区切り複数指定(ホスト名を先頭)
./ssj ai2 38082:ai2:8080,38085:ai5:8080
@形式(従来の方法):
# RHOST 上のポートへ転送
./ssj -L 8080:80@remote.example.com
# RHOST 経由で別のホストへ転送
./ssj -L 8080:192.168.1.1:80@remote.example.com
スペースなし形式:
./ssj -L8080:80@remote.example.com
リバーストンネル (Reverse tunnel)
./ssj -R 8080:80@remote.example.com ./ssj -R 8080:192.168.1.1:80@remote.example.com
カンマ区切りリバーストンネル(新機能)
./ssj -R ai2 48082:11430,48085:ai5:8080
トンネル削除(シリアル番号指定)
./ssj -d 1
全トンネルを削除(プロテクトされているものは除く)
./ssj -R
トンネルの疎通テスト
./ssj -t
特定シリアルの疎通テスト
./ssj -t 1
ヘルプ表示
./ssj -h
### オプション一覧 (Options)
| オプション | 説明 | 例 |
|------------|------|-----|
| (none) | List sessions | `./ssj` |
| `-L LPORT:RPORT@RHOST` | Local forward | `./ssj -L 8080:80@host` |
| `-L LPORT:DEST:RPORT@RHOST` | Local forward (via RHOST) | `./ssj -L 8080:192.168.1.1:80@host` |
| `-L LPORT:RHOST:RPORT` | Local forward (legacy) | `./ssj -L 2222:host:22` |
| `-L HOST PORTS` | Local forward (カンマ区切り複数ポート) | `./ssj -L host 8080:80,8081:81` |
| `-R LPORT:RPORT@RHOST` | Reverse tunnel | `./ssj -R 8080:80@host` |
| `-R LPORT:DEST:RPORT@RHOST` | Reverse tunnel (via RHOST) | `./ssj -R 8080:192.168.1.1:80@host` |
| `-R HOST PORTS` | Reverse tunnel (カンマ区切り複数ポート) | `./ssj -R host 8080:80,8081:81` |
| `-R` | Delete all tunnels (except protected) | `./ssj -R` |
| `-d SERIAL` | Delete tunnel | `./ssj -d 1` |
| `-P SERIAL` | Protect tunnel | `./ssj -P 1` |
| `-U SERIAL` | Unprotect tunnel | `./ssj -U 1` |
| `-U` | Unprotect all tunnels | `./ssj -U` |
| `-t` | Test all tunnels | `./ssj -t` |
| `-t SERIAL` | Test specific tunnel | `./ssj -t 1` |
| `--stop` | Stop all tunnels | `./ssj --stop` |
| `-f` | Force overwrite (port in use) | `./ssj -f -L 8080:80@host` |
| `-q` | Quiet mode | `./ssj -q` |
| `--color` | Enable color (default) | `./ssj --color` |
| `--no-color` | Disable color | `./ssj --no-color` |
| `-h, --help` | Show help | `./ssj -h` |
## 使用例 (Examples)
### SSH ポートフォワーディング (SSH Port Forwarding)
```bash
# リモートサーバの SSH ポートにローカルポート 2222 でフォワード
./ssj -L 2222:22@remote.example.com
# Web サーバのポート 80 をローカルポート 8080 でフォワード
./ssj -L 8080:80@web.example.com
# リモートサーバ経由で別ホストのポートへフォワード
./ssj -L 3306:192.168.1.100:3306@gateway.example.com
# カンマ区切りで複数のポートをまとめて指定(新機能)
./ssj -L ai2 48082:11430,48085:ai5:8080,48083:ai.k1:8080
# bare引数でホスト名を指定 + カンマ区切り(新機能)
./ssj ai2 48082:11430,48085:ai5:8080
リバーストンネル (Reverse Tunnel)
# ローカルポート 8080 をリモートサーバ上で公開
./ssj -R 8080:80@remote.example.com
# ローカルの開発サーバをリモートからアクセス可能に
./ssj -R 3000:3000@remote.example.com
プロテクト機能 (Protect Feature)
# 重要なトンネルをプロテクト
./ssj -P 1
# プロテクトを解除
./ssj -U 1
# 全プロテクトを解除
./ssj -U
テストと監視 (Test and Monitoring)
# 全トンネルの疎通テスト
./ssj -t
# 特定のトンネルをテスト
./ssj -t 1
# 全トンネルを停止
./ssj --stop
ファイル構成 (File Structure)
/home/user/ssj/
├── ssj # 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/ssj/ ディレクトリに以下のファイルを使用します:
Session management uses the following files in ~/.local/share/ssj/:
~/.local/share/ssj/
├── 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/ssj/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/ssj/logs/に保存されます
トラブルシューティング
トンネルが接続できない
- リモートホストとポートの確認
- SSH キーまたはパスワード認証の確認
- ファイアウォール設定の確認
- ログの確認:
~/.local/share/ssj/logs/ssj.log
ウォッチャーが動作しない
- ウォッチャーの PID ファイル確認:
cat ~/.local/share/ssj/watcher.pid - プロセスの生存確認:
ps -p <PID> - ログの確認:
~/.local/share/ssj/logs/ssj.log
開発
テスト
# 構文チェック
bash -n ssj
# テスト実行(如果有り)
cd tests
./test_all.sh
コントリビューション
- このリポジトリをフォーク
- 機能ブランチを作成:
git checkout -b feature/my-feature - 変更をコミット:
git commit -m 'feat: 機能の追加' - ブランチをプッシュ:
git push origin feature/my-feature - プルリクエストを作成
ライセンス
MIT ライセンス(またはプロジェクトのライセンス)
作者
krasherjoe
バージョン
- 現在: v2.1.2
- 最終更新: 2026-07-17