Mac/リモートのファイルシステムをSSH経由でマウントする

Mac/リモートのファイルシステムをSSH経由でマウントする

OSX 10.9 Mavericks 編

基本的↓の Lion と同じかな

$ brew install sshfs

で何の問題もなく全部インストールされた。

そして Lion 同様に

$ sudo /bin/cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.2/Library/Extensions/fuse4x.kext /Library/Extensions
$ sudo chmod +s /Library/Extensions/fuse4x.kext/Support/load_fuse4x

とりあえず再起動

OSX 10.7 Lion 編

sshfsを使う

sshfsというプログラムを使うとsshでの接続先をMac上のファイルシステム上にマウントできるらしい。

このプログラムを使う口をMac側に作らないと行けないようなのだが、この口にあたるアプリがMacFUSEと言うらしい。 しかしこのMacFUSEが2008年あたりで開発が止まっているらしく、Lionに対応していないっぽい。

いろいろ調べると後継のプロジェクトがあってFUSE for OSX(通称OSXFUSE)というプロジェクトとして継続しているみたいなのだがなんだが周辺ツールが過去を引きずっているみたいでよくない

さらに調べるとfuse4xというMacFUSE的な動きをするツールがあって、これとsshfsの組み合わせがよさそうだ。

sshfsのインストール

brewでインストールすると楽。

$ brew install sshfs

とやるといろいろ依存性も考慮した上でビルドしてくれる。その中にfuse4xも入っている。

この時に色々brewがあれこれやれと言ってくるので支持に従う。

自分はビルドの途中で

Could not symlink file: /usr/local/.............

みたいなことを言われた。

該当ディレクトリの権限を見るとroot:wheelになっていたので

$ chown -R hoge:admin /usr/local/...........(省略)

として変更してしまう。変更していいのだろうか・・・w

その後linkだけやり直した

$ brew link fuse4x

な感じ、リンクできた。

このfuse4xという仕組みはkernelのextensionとして働くらしくここにさらに一手間ある。

$ brew info fuse4x-kext
fuse4x 0.9.0
http://fuse4x.org/
Depends on: automake, libtool, gettext, fuse4x-kext
/usr/local/Cellar/fuse4x/0.9.0 (16 files, 676K) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/fuse4x.rb
hoge:Extensions hoge$ brew info fuse4x-kext
fuse4x-kext 0.9.0
http://fuse4x.org/
/usr/local/Cellar/fuse4x-kext/0.8.14 (7 files, 312K)
/usr/local/Cellar/fuse4x-kext/0.9.0 (5 files, 288K) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/fuse4x-kext.rb
 
==> Caveats
In order for FUSE-based filesystems to work, the fuse4x kernel extension
must be installed by the root user:
 
  sudo cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.0/Library/Extensions/fuse4x.kext /Library/Extensions
  sudo chmod +s /Library/Extensions/fuse4x.kext/Support/load_fuse4x
 
If upgrading from a previous version of Fuse4x, the old kernel extension
will need to be unloaded before performing the steps listed above. First,
check that no FUSE-based filesystems are running:
 
  mount -t fuse4x
 
Unmount all FUSE filesystems and then unload the kernel extension:
 
  sudo kextunload -b org.fuse4x.kext.fuse4x

つまりインストールを完了させるには

sudo cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.0/Library/Extensions/fuse4x.kext /Library/Extensions
sudo chmod +s /Library/Extensions/fuse4x.kext/Support/load_fuse4x

をやれということだ

ここで一旦Mac再起動自体を再起動しておく。

外部のサーバをマウントしてみる

ホームディレクトリに適当にマウントポイントになるディレクトリを作る

$ mkdir mnt

その後に

$ sshfs hoge@192.168.11.100:/home/hoge mnt

みたいな感じで

$ sshfs ユーザー@サーバ:サーバ上のディレクトリ マウントポイント

と書くと接続できる

マウントの解除は

$ umount mnt

これであらゆるアプリで透過的にサーバ上のファイルが扱えるようになった。

現実の運用として

透過的にネットワーク上のファイルをローカルファイルのように編集するのは問題ない。

しかし大量にファイルを消したり、ディレクトリ構成を変えたり、大量にファイルをアップロードしたりするファイル自体のオペレーションには向かない。 スピードが遅すぎる。

バージョン

  • 2012-06-19 インストール方法を追記
  • 2012-06-19 新規

タグ

mac/mount_remote_filesystem_via_ssh.txt · 最終更新: 2013-12-23 18:04 by ore