SSHFS

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page SSHFS and the translation is 88% complete.
Other languages:
Resources
This article has some todo items:
  • Add instructions for using SSHFS with more desktop environments.
  • Extra details would help.

SSHFS (SSH File System) は リモートファイルシステムをローカルマシンにマウントするために使用される、セキュアシェルのクライアントです。SSHFS は、ユーザが簡単にアクセスできる場所にファイルシステムをマウントするために、そして SFTP プロトコルを介してファイルにアクセスするために、Filesystem in Userspace (FUSE) を使用します。

インストール

カーネル

SSHFS は FUSE を使用するので、これをカーネルで有効化する必要があるでしょう。

カーネル カーネルで FUSE を有効化する
File systems  --->
   [*] FUSE (Filesystem in Userspace) support
メモ
When enabling a built-in (non-modular) feature or driver in the kernel remember a recompile will be needed and the new kernel loaded into memory (system reboot) before changes will take effect. This step should be completed before moving on to other sections in this article.

USE フラグ

現時点で SSHFS に利用可能な USE フラグはありません。

Emerge

emerge コマンドを使用して、net-fs/sshfs をインストールするように Portage に指示してください:

root #emerge --ask net-fs/sshfs

設定

権限を設定する必要があるかもしれません。そうしないと、マウント時に "fuse: failed to open /dev/fuse: Permission denied" エラーが発生することがあります。まずは試してみて、必要であればこの節に戻ってきてください。

上のエラーに遭遇した場合、まずは SSHFS の使用が許可されるアカウントのためのグループを作成し、アカウントをそのグループに追加してください:

root #groupadd crypto
root #usermod -aG crypto $USERNAME

必要であれば、新しいグループ権限を適用するために再ログインしてください。

その後、/etc/udev/rules.d/60-fuse.rules ファイルを作成し、以下の内容を追加してください:

ファイル /etc/udev/rules.d/60-fuse.rules
KERNEL=="fuse", NAME="%k", MODE="0666", GROUP="crypto"

変更を適用するために fuse モジュールをリロードしてください:

root #modprobe -r fuse
root #modprobe fuse
root #ls -l /dev/fuse
crw-rw-rw- 1 root crypto 10, 229 Nov  8 22:29 /dev/fuse

使い方

マウントする

SSHFS を使用するためには、リモートマシン上で SSH デーモンが実行中である必要があり、sftp サブシステムが有効化されている必要がある場合があり、さらに少なくとも 1 ユーザが SSH を介してマシンにアクセスできるように設定されていなくてはなりません。

リモートファイルシステムをローカルにマウントするためには、正しい認証情報が必要になるでしょう。コマンドライン上でユーザ名が与えられない場合は、現在のユーザ名がデフォルトで使用されます。例えば、ユーザ larry が現在システムでアクティブなユーザで、次のコマンドを実行すると:

larry@example $sshfs remotehost:/home/larry ~/remote_mount

ユーザ名 larry がリモートシステムへと送信されるので、larry という名前のリモートアカウントにアクセスするための認証情報が必要になるでしょう。larry のパスワードを入力すると、これはリモートのユーザ larry のホームディレクトリをローカルマシン上のディレクトリ ~/remote_mount にマウントするでしょう。先のコマンドはこのコマンドを実行するのと等価です:

larry@example $sshfs larry@remotehost:/home/larry ~/remote_mount

ユーザを変更するためには、IP アドレスまたはドメイン名の前にユーザの名前を入力してください。例えば、リモートシステムの root ユーザ名とパスワードを使用してリモートシステムにログインするためには、以下を使用してください:

user $sshfs root@remotehost:remotehost:/ ~/remote_mount

このためにはサーバ上で root アクセスが有効化されていなくてはなりません。

Sudo

If a user can sudo on the remote host to another user, it may be possible to access files as that user on the remote host (if the access to sudo does not need a password). For example, if a user can su to root on the remote host without entering a password, mount with:

user $sshfs -o sftp_server="/usr/bin/sudo /usr/lib64/misc/sftp-server" larry@remotehost:/path/to/remote/system /path/to/local/sshfs/mount

These paths are valid for a default Gentoo installation on the remote host, they may need to be changed if the server is running other distributions.

メモ
This may not be a particularly secure method of accessing the server, caution advised.

アンマウントする

SSHFS を持つディレクトリをアンマウントするには、-u オプション付きで fusermount コマンドを使用してください:

larry@example $fusermount -u /path/to/local/sshfs/mount

Permissions based options

In order to have read/write access to a mounted remote directory the allow_other and/or allow_root options may be needed, depending on if the user is root or a regular user. Simply enable as shown below (replace allow_other with allow_root, if root).

larry@example $sshfs -o allow_other larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint

Alternatively, the uid, gid, and umask options can be used to further fine tune permissions. When setting multiple options at the same time use a space separated list after a single -o.

コード umask, uid, gid オプション
-o umask=M
    set file permissions (octal)

-o uid=N
    set file owner

-o gid=N
    set file group
メモ
The use of these options may output an error, "fusermount3: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf". In this case, just uncomment the "user_allow_other" line in that file and try again.

接続を自動化する

For remote file systems that need to be mounted frequently, it is the sign in process may be automated. Automation can be achieved by using a public/private SSH key pair combined with a mechanism to mount the remote filesystem on a specific event (user login, or system boot for example).

The first step is to setup the SSH key pair on the local and remote machines. Visit the Passwordless Authentication section of the SSH article for further instructions on how set up an SSH key pair. When finished return to this article.

After the key pair has been created and properly set up, determine what event will be used to start the connection automatically. It is common for a system to attempt to remotely mount a file system upon user login or system boot. Controlling the sshfs mount depends on what software the user will be implementing in their local environment. There are several ways to handle the task.

fstab

sshfs はシステムの /etc/fstab ファイル内で使用することができます。これにより、ネットワーク越しのファイルシステムを、ローカルファイルシステムのマウントとして機能するように割り当てることができます。sshfs を使用するファイルシステムはわずかに異なるマウントオプションを必要とするので、それぞれのユースケースでオプションが正しいことを確認するために、man ページを確認してください。fstab で sshfs を使用する例:

ファイル /etc/fstabsshfs を fstab に追加する
# 接続時に自動的に ~/Music をマウントする
sshfs#SERVER_USER@remotehost:/SOURCEDIR /home/USER/Music fuse user,_netdev,idmap=user,transform_symlinks,identityfile=/home/USER/.ssh/id_rsa,allow_other,default_permissions,uid=1000,gid=1000 0 0

ログインシェル

多くのシェルは、ユーザのログインまたはログアウト中に実行されるコマンドのサポートを含んでいます。この節では組み込みシェルスクリプトを使用して接続を自動化する方法の例を提供します。

先に進む前に、どのシェルが使用されているかを知る必要があります。どのシェルが使用されているか判別するために、対象のユーザとして以下のコマンドを実行してください:

user $echo $SHELL

考えられる出力は:

  • bash なら /bin/bash
  • sh なら /bin/sh
  • tcsh (csh) なら /bin/tcsh
  • zsh なら /bin/zsh
メモ
利用可能なシェルに関するさらなる情報については、シェルの記事を参照してください。
Bash

bash シェルを使用している場合は、ユーザのホームディレクトリ内に ~/.bash_login および ~/.bash_logout ファイルを作成し、sshfs コマンドをファイルに追加してください。

user $touch ~/.bash_login ~/.bash_logout

シェルログイン時のマウント:

ファイル ~/.bash_loginbash ログインシェルに sshfs マウントを追加
# ユーザログイン時にリモートディレクトリをマウントするために追加
sshfs larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint

シェルログアウト時のアンマウント:

ファイル ~/.bash_logoutbash ログアウトシェルに sshfs アンマウントを追加
# ユーザログアウト時にリモートディレクトリをアンマウントするために追加
fusermount -u /path/to/local/sshfs/mountpoint
Sh
user $touch ~/.profile
ファイル ~/.profilesh ログインシェルに sshfs マウントを追加
# ユーザログイン時にリモートディレクトリをマウントするために追加
sshfs larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint
Zsh
user $touch ~/.zlogin
ファイル ~/.zloginzsh ログインシェルに sshfs マウントを追加
# ユーザログイン時にリモートディレクトリをマウントするために追加
sshfs larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint
Tcsh (Csh)
user $touch ~/.login
ファイル ~/.logintcsh または csh ログインシェルに sshfs マウントを追加
# ユーザログイン時にリモートディレクトリをマウントするために追加
sshfs larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint

デスクトップ環境

多くのデスクトップ環境は、自動的にプログラムを開始するための方法を含んでいます。

Openbox

Openbox は各ユーザのホームディレクトリ内に配置される autostart ファイルを使用します。

ファイル ~/.config/openbox/autostartOpenbox autostart ファイルに sshfs マウントを追加
# ユーザログイン時にリモートディレクトリをマウントするために追加
sshfs larry@remotehost:/path/to/remote/directory /path/to/local/sshfs/mountpoint &
メモ
Openbox の autostart ファイル内で実行されるコマンドの終端に & (アンパサンド) を含めるのは重要です。

関連項目

  • CurlFtpFS — allows for mounting an FTP folder as a regular directory to the local directory tree.
  • SCP — an interactive file transfer program, similar to the copy command, that copies files over an encrypted SSH transport.
  • SSH — リモートマシンに安全にログインし、作業を行うためのユビキタスなツールです。
  • SFTP — an interactive file transfer program, similar to FTP, which performs all operations over an encrypted SSH transport.

外部資料