Wednesday, July 30, 2008

How To Mount Remote Folder Location Via SSHFS




File transfers between hosts can be secured by using SSH protocol. Transferring files from current to remote location can easily be done from terminal using the scp linux command. However, it would be more convenient to have those remote folders and files be mounted locally from our own drive and access them locally using a local file browser or using local terminal file commands. Here's how you can mount a remote location into the local's file system.

Introducing SSHFS

This is a FUSE-filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol, it is very easy to set up. On the client side, mounting the filesystem is as easy as logging into the server with ssh.

SSH File System Installation

Yum can install fuse sshfs rpm package.

# yum -y fuse-sshfs

Mount Remote Folder via Fuse SSH File System

To mount /home/john from 192.168.100.1 to local folder /mnt/remote using a remote system account john

# sshfs john@192.168.100.1:/home/john /mnt/remote

Enter password details as required.

Say we need to mount a remote sub folder named /home/peter from a remote host with IP address 192.168.100.1 and mount it into our local file system folder /mnt/remote2 by using a remote john account, simply

#sshfs john@192.168.100.1:/home/peter /mnt/remote2

The above would mount the delegated folder. As long as you have read and/or write access to files and subfolders under /home/peter remote location, you would be able to mount it successfully.

The above mounts /home/john folder from 192.168.100.1 locally into /mnt/remote using remote's john account. This should work out right without any SSH restrictions, access list and firewalls from the remote location.

Now, access remote files and folder locally from your current file system

# cd /mnt/remote

# ls -la

Fuse SSH File System Troubleshooting

If any errors persists, simply check for fuse kernel module

# modproble -l fuse

The above should give you a similar line below which tells that fuse kernel module is currently loaded

/lib/modules/2.6.25-14.fc9.i686/kernel/fs/fuse/fuse.ko

Fuse SSH file system approaches the concept of having to update current file system status locally from your system and resync to remote location for any changes, ofcourse, naturally, there would be a split second delay on any local file changes, depending on connection speed.

SSH file system is a great remote file management convenience besides from having to use scp for every remote file transfers.

4 comments:

Henry said...

you mean

# modprobe -l fuse

(ie not modproble)

I am getting 'connection reset by peer' - is this permissions?

VeRTiTO said...

it could be permission. you could try to check your selinux settings

my current fuse-sshfs version is

fuse-sshfs-2.0-1.fc9.i386

and my kernel

# uname -a
2.6.25-14.fc9.i686

thanks for the comment!

Henry said...

I go it working but not in /etc/fstab which I was trying for.

It's odd - it only works if the user is 'henry' (ie the current user on the client machine) and the owner of the mountpoint is 'henry' (ie the same as the current user) and the host user is 'henry' - ie all three the same.

Possibly it's because my client machine is Ubuntu and the host is Centos and I've set them up with the same user-id for my user ('henry') but 'root' has different user-ids.

VeRTiTO said...

that is weird.

what is important is the user account you were using to ssh via ssh-fs is existing from the remote machine and have file/group access from the files/folders that would be mounted. as an example

sshfs john@192.168.100.1:/home/john /mnt/remote

john is a user account from remote host with an IP of 192.168.100.1

with your issue, you should check your mount point if it is ONLY owned by user account henry, otherwise it will fail.

cheers

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy