10
5

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.

sshfsを使ってみた

Last updated at Posted at 2018-05-05

手元のマシンでSFTP環境を仮想的にマウントできるsshfsを便利に使ってみましょう!
※sftpとftpsは別物です。ftpsはftp over ssl、こちらはfile over sshです。

sshfsとは

sshfsとは、fuseの一種で、あたかもsftp先のサーバーを自分のマシンのディレクトリとしてマウントできるものです。手元のマシンでそこに新しくファイルを作成すると、sftp先にも同じファイルが転送されます。まあ自動ミラーリングみたいなものです。

インストール

Archなので以下でした

$ sudo pacman -S sshfs

マウント

どうやらsftp先はホームディレクトリのchroot監獄になっているようなので、素直に/を指定しましょう。

$ mkdir ~/kosenspace
$ sshfs hoge@kosen.space:/ ~/kosenspace -o IdentityFile=~/.ssh/fuga

はい、これだけで完了です。
ただ、パーミッションが何故かrootのみになっていたり色々と怪しいので、後述の自動マウントを使います。

自動マウント

/etc/fstabに追記するだけでいいようです。

hoge@kosen.space:/  /home/hoge/kosenspace  fuse.sshfs noauto,x-systemd.automount,_netdev,user,idmap=user,follow_symlinks,identityfile=/home/hoge/.ssh/huga,allow_other,default_permissions,uid=1000,gid=998 0 0

最後のUIDとGIDはidコマンドで確認できます。
これで、起動時に自動でマウントがされるようになりました。

10
5
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
10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?