6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windowsで多段ssh先のディレクトリをsshfsで手元にマウントする

Last updated at Posted at 2018-08-22

導入

Sshfs Managerを入れる

導入手順外部リンク
これを入れるとタスクバーに常駐する。
taskbar.png
アイコンをクリックして設定する(赤字の変数は後述)
sshfs_manager.png

備考:失敗したsshfsクライアント

billziss-gh/sshfs-win

  • powershellからProgram Files/SSHFS-Win/bin/sshfs.exeを直に叩く
    • オプションの書式が違うって怒られた
  • SiriKali(↑のGUIフロントエンド)
    • CreateVolume→Sshfsで設定入力してAdd押したのに反映されない
    • そもそも設定にdomain欄はあってもport欄がない

シェルスクリプト

springboardに手作業でsshして下を実行してみて怒られたら$springboard_portを空いているポートに変えてください。

 $ ssh -fNL ${springboard_port}:localhost:${target_port} ${target_user}@${target_domain}
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 10023
Could not request local forwarding.

init_sshfs.sh

# !/bin/bash
target_domain=''
target_user=''
target_port=22
springboard_domain=''
springboard_user=''
springboard_port=10023 #適当な空いているポート
client_port=10022 #適当な空いているポート

ssh ${springboard_user}@${springboard_domain} \
	"ssh -fNL ${springboard_port}:localhost:${target_port} ${target_user}@${target_domain}"
ssh -fNL ${client_port}:localhost:${springboard_port} ${springboard_user}@${springboard_domain}
  • WSLに↑のinit_sshfs.shを保存してchmod +xしておく
  • {target,springboard,client}_{domain,user,port}の変数を書き換えておく
  • 踏み台サーバーにsshできるよう~/.ssh/を設定しておく

動作原理

ssh のポートフォーワードを利用している。sshでアクセス可能なら任意のポート同士をつなげることができる。
今回はtargetの22番ポートを踏み台を経由してlocalの10022ポートにつないでいる。
詳しい解説:京大マイコンクラブ 楽しいトンネルの掘り方
範囲を選択_001.png

実行

  • 先にinit_sshfs.shを実行する
  • Sshfs Managerから設定したドライブへMountする
  • エクスプローラからマウントしたドライブが確認できれば成功

後始末

  • Sshfs ManagerからUnMountする
  • WSLでpgrep -a sshして-fNLオプションのをkillする
    • 踏み台にsshして同様にkillする

後始末もスクリプト書いて自動化したいんですが、killallでオプションとか全一致で殺せませんかね…

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?