Skip to content

Instantly share code, notes, and snippets.

@koki-h
Last active September 25, 2020 10:22
Show Gist options
  • Select an option

  • Save koki-h/b7f7420d259e1bd2bd19bbd3d931a4b5 to your computer and use it in GitHub Desktop.

Select an option

Save koki-h/b7f7420d259e1bd2bd19bbd3d931a4b5 to your computer and use it in GitHub Desktop.
sshトンネリングいろいろ
#リモートホスト(serversman.gohannnotomo.org)の8081にアクセスが有った時にローカルホストの8081が応答するようなssh。
# 8081はmotionのストリーミングを想定
#ローカルホストから実行する
ssh -N serversman.gohannnotomo.org -R 8081:localhost:8081
# 8081がhttpで喋っている場合、リモートホストから更に外部に公開したい場合はリモートホストのhttpd.confに追記
ProxyPass /motion http://localhost:8081
#リモートホスト(serversman.gohannnotomo.org)からローカルホストへsshできるようにする
ssh -N serversman.gohannnotomo.org -R 2222:localhost:22
#リモートからは以下のようにするローカルへssh接続できる
# ssh pi@localhost -p 2222
@koki-h
Copy link
Copy Markdown
Author

koki-h commented Jun 26, 2017

#autosshを使用する場合(ローカルの22番をリモートの10022版に繋げる。-pはリモートのsshポートを指定する)
autossh -f -C -N -R 10022:localhost:22 -p 22 user@example.com
#rc.localから起動するとうまくいかないみたい。→rootユーザの設定不足だったらしい(authorized_keys)。

@koki-h
Copy link
Copy Markdown
Author

koki-h commented Jun 28, 2017

autosshをバックグラウンドで起動し、プロセスIDを取得する

#autossh起動ユーザが/run/lock/motion_for_mukoyama/の所有者である必要がある。
$ AUTOSSH_PIDFILE=/run/lock/motion_for_mukoyama/autossh 
$ nohup autossh  -N -R 10022:localhost:22 serversman.gohannnotomo.org &
$ cat /run/lock/motion_for_mukoyama/autossh
2040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment