手順
• systemdひな形取得
• curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/autossh@host1 | ¥
• sudo tee /etc/default/autossh@example
• curl -sSL https://gist.githubusercontent.com/ttimasdf/ef739670ac5d627981c5695adf4c8f98/raw/
[email protected] | ¥
• sudo tee /etc/systemd/system/
[email protected]
• 専用ユーザ作成(自宅サーバ、会社サーバ両方)、公開鍵作成、ssh接続
• sudo useradd -g nogroup -s /bin/false -m tunnel
• sudo -u tunnel mkdir -p ~tunnel/.ssh
• sudo -u tunnel nano ~tunnel/.ssh/config
• sudo -u tunnel ssh remote.example.com #自宅サーバ
• (設定ファイル名変更:オプション)
• cp /etc/default/autossh@example /etc/default/autossh@hoge
• 設定変更
• sudo nano /etc/default/autossh@example
• /etc/default/autossh@example内の次の2行を編集する
• TARGET_HOST=remote.example.com
• 接続サーバ(自宅サーバ)
• FORWARDS=-R 10022:127.0.0.1:22
• -Rオプション:リバースポートフォワード 、10022(任意:自宅サーバ側の空ポート番号)、22(会社サーバでの既存sshポート番号)
• 接続
• sudo systemctl start
[email protected]
• 永続化
• sudo systemctl enable
[email protected]
自宅サーバ
会社サーバ
sshdport
へ転送
会社サーバ
作業PC
ssh client
sshd
sshd
autossh
systemd
制御監視