Mounting Directories via SSH

For mounting directories from a remote machine, usually NFS or SMB/CIFS is used which requires a running file server. On many linux servers, however, all you have is a shell account, so file transfer has to be done via scp.

Using the FUSE Linux kernel module, which provides user space filesystems and its sshfs client, you can mount remote directories from machines where all you have is an SSH account. If you can log in via SSH you can also mount the directory, there is no need to modify or configure anything on the remote machine.

On the client machine, you have to install FUSE and sshfs. If you’re running Ubuntu, execute the following command:

  sudo apt-get install sshfs

To get the permissions to use FUSE on your local machine, your user has to belong to the fuse group. This can be achieved using vigr(8), for example. Don’t forget to log out and in again for the change to take effect. You can see which groups you are part of using the groups or id commands. From this point on, you can work without root privileges.

The next step is to create a local mount point on the client machine (using the hostname of the remote machine would be a good convention to follow):

  mkdir mountpoint

Now you can mount the remote directory:

  sshfs remote_username@remote_hostname:/home/media mountpoint

This mounts the /home/media directory on the remote server. If you want to mount your remote home directory and the user names on the local and remote system are the same, the command can be even shorter:

  sshfs remote_hostname: mountpoint

When you’re done, you can umount the directory:

  fusermount -u mountpoint

Check the sshfs(1) manpage for more information, like mapping user IDs or performance tuning.

Advertisements
This entry was posted in tools and tagged , , , . Bookmark the permalink.

One Response to Mounting Directories via SSH

  1. Pingback: Unmaintainable

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s