SSHFS

SSHFS (SSH File System) is Article description::a secure shell client used to mount remote filesystems to local machines. SSHFS uses Filesystem in Userspace (FUSE) to mount filesystems in a location users can easily access, and accesses files over the SFTP protocol.

Kernel
Since SSHFS uses FUSE it will need to be enabled in the kernel.

USE flags
There are currently no available USE flags for SSHFS.

Emerge
Use the command to ask Portage to install :

Configuration
Permissions may need to be set, or mounting may produce a "fuse: failed to open /dev/fuse: Permission denied" error. Try first, and come back to this section, if necessary.

If the above error is encountered, first create a group for those who will be allowed to use SSHFS, then add the accounts that will use it, to the group:

Log user out then in, if needed, to apply new group permissions.

Now create the file and add the following contents:

Reload  module, for changes to apply:

Mounting
In order to use SSHFS, an SSH daemon needs to be running on the remote machine, the sftp subsystem may need to be activated, and at least one user must be configured to be able to access the machine via SSH.

To mount a remote file system locally, the right credentials will be needed. If no user name is given on the command line, the current user name will be used by default. For example, if the user larry is currently the active user on the system, and this command is run:

The username larry will be sent to the remote system, so the credentials for access to a remote account named larry will be needed. After entering the password for larry, this would mount the remote home directory of the user larry to a directory on the local machine. The previous command is the equivalent of running this command:

To change the user, put the name of the user before the IP address to domain name. For example, to login to the remote system using the remote system's root user name and password, use:

Root access must be enabled on the server for this.

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 acess 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:

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.

Unmounting
To unmount a directory with SSHFS use the command with the   option:

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).

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.

Automating the connection
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 mount depends on what software the user will be implementing in their local environment. There are several ways to handle the task.

fstab
can be used inside a system's file. This enables over-the-network filesystems to be assigned to act as local filesystem mounts. Filesystems using sshfs require slightly different mount options, so be sure to look at the man page to be sure the options are correct in each use case. A example of using sshfs in fstab:

Login shells
Most shells include support for commands to be executed during user login or logout. This section will provide examples on how to automate the connection using built in shell script.

Before proceeding, it is necessary to know which shell is being used. Execute the following command as the user of interest to determine which shell is being used:

Possible output:


 * for
 * for
 * for
 * for

Bash
When using a bash shell, create a and  files in the user's home directory and add the sshfs command to the file.

Mount on shell login:

Unmounting on shell logout:

Desktop environments
Most desktop environments include methods for automatically starting programs.

OpenBox
OpenBox uses the file located in each user's home directory.

External resources

 * SSHFS help page on Github
 * SSHFS tutorial at LinuxJournal.com