Sonora Communications, Inc.

  • Increase font size
  • Default font size
  • Decrease font size

SSHFS - Simple Remote Filesystem Access

E-mail Print PDF

An easy way to access remote Linux filesystems from another Linux computer is to use SSHFS. It is probably easier than implementing NFS or SMB and it is far more secure as it only requires the SSH port (22) to be open.

Suse to SME Server Example (Beta)

On the SME 7.x Server

Install the Remote User Access contrib:

yum install -y --enablerepo=smecontribs smeserver-remoteuseraccess

Enable the bash shell for the user to give remote access and modify the chroot as appropriate...probably /home/e-smith/files/home or /home/e-smith/files.

Create a new file /usr/local/bin/sftp-wrapper

vi /usr/local/bin/sftp-wrapper

then add:

#!/bin/sh
umask 002
exec /usr/libexec/sftp-server "$@"

Set the permissions:

chmod 755 /usr/local/bin/sftp-wrapper

On the Suse 10.1 Workstation

As root, install the sshfs and fuse rpms.

yast --install sshfs fuse

As the regular user, perform the following commands. Create a mount point to mount the server's filesystem.

mkdir -p ~/servername/filesystemname

(ex: mkdir -p ~/linus/company)

If an ssh key pair already exists, skip this step. Hit 'enter' when prompted for a passphrase.

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

Use copy/paste to import the workstation user's public key into the server user's authorized_keys (keyring) using the new Server-Manager Remote User Access panel.

Add the following (plus a space) to the beginning of the new key.

command="/usr/local/bin/sftp-wrapper"

(ex: command="/usr/local/bin/sftp-wrapper" ssh-rsa ...)?

Mount the remote filesystem.

su -c 'modprobe fuse' (if the new fuse kernel module is not already loaded)
sshfs username@servername:/path/to/filesystem /path/to/mountpoint

(ex: sshfs gcooper@linus:/home/e-smith/files/ibays/
company/files ~/linus/company)

Unmount remote filesystems.

fusermount -u /path/to/mountpoint

Mount Script

#! /bin/bash
# mount.sh
# Gene Cooper (gcooper AT sonoracomm.com)
# 5/31/06
# This script mounts sshfs file shares from a server.
# Install sshd on the server. Install fuse and sshfs on the workstation.
#
# install workstation user's public key to server's authorized_keys2 file
#
# set umask to 002 so files created on the server are group-writable
umask 002
#
# mount the shares to mountpoints in home directory
sshfs gcooper@sol:/home/e-smith/files/ibays/family/files ~/sol/family
sshfs gcooper@sol:/home/e-smith/files/ibays/pub/files ~/sol/pub
sshfs gcooper@sol:/home/e-smith/files/users/gcooper/home ~/sol/home

Dismount Script

#! /bin/bash
# mount.sh
# Gene Cooper (gcooper AT sonoracomm.com)
# 5/31/06
#
# This script dismounts sshfs file shares from a server
#
# dismount the shares like this
fusermount -u ~/sol/family
fusermount -u ~/sol/pub
fusermount -u ~/sol/home

KDE Integration (beta)

Create startup and shutdown scripts and place them in the regular user's .kde/Autostart and .kde/shutdown directories.

#! /bin/bash
sshfs gcooper@linus:/home/e-smith/files/ibays/company/files ~/linus/company

and

#! /bin/bash
fusermount -u ~/linus/company

Gnome Integration (beta)

Within Gnome

Desktop -> Preferences -> More Prefs -> Sessions -> Add

/usr/bin/sshfs -f user@host:/path /mountpoint

Modify the $HOME/.Xclients-default script to unmount the filesystem upon logging out. Note that this file is rewritten when using the switchdesk utility.

# dismount sshfs filesystems
for p in $WMPATH ; do
[ -x $p/$WM ] && $p/$WM; fusermount -u /mountpoint; exit 0
done

More Info

Here.?

Last Updated on Thursday, 22 January 2009 07:22  

Your external IP

You are connecting to this site from: 38.107.179.231

Secure Client Login

Email Address:

Password: