Jan
25
Posted on 25-01-2007
Filed Under (Debian & Ubuntu) by Arun Bagul

Introduction –

SSH (Secure Shell) is mostly used to login to remote shell (Linux/Unix machine). SSH is protocol to transfer files securely like FTP, but more secure. Transferring files to an from an ssh account can be done using the scp command. What if you could mount a remote folder that you can access using ssh on your local computer? What if you could access files on an ssh account just like they were local files on your pc? Well now you can! mount a folder in an ssh account, edit the files locally and save the files, that’s it! The file will be saved on remote ssh server.

sshfs is a tool, which allow us to mount directory file systems over ssh on Ubuntu. sshfs is a filesystem client based on the SSH File Transfer Protocol.
Most SSH servers already support this protocol it is very easy to set up on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

How to install sshfs –

root@arunbagul:~# apt-get  install   sshfs
Reading package lists… Done
Building dependency tree

….
root@arunbagul:~#

This will also install fuse-utils and libfuse2, which are required.

What is required ?

fuse is the kernel module which need to loaded –

root@arunbagul:~# lsmod | grep fuse
fuse 47124 3
root@arunbagul:~#

If this module is not loaded, you will get following error-

fusermount: fuse device not found, try ‘modprobe fuse’ first

** Use below command to load ‘fuse’ module

root@arunbagul:~# modprobe fuse
root@arunbagul:~#

If you want to load ‘fuse’ modules on startup. Then edit the file /etc/modules and adding a ‘fuse’ on new line at the end.

** Now create a local directory where you want the files to be mounted…

root@arunbagul:~# mkdir /media/ssh_file_system
root@arunbagul:~#
root@arunbagul:~# chown arun:arun /media/ssh_file_system
root@arunbagul:~#

Once you have done the above, you can use sshfs to mount the remote directory to your local system!

Say I want to mount the “/var/www” directory on my remote server (192.168.0.1) I would do it by executing the following command…

root@arunbagul:~# sshfs root@192.168.0.1:/var/www /media/ssh_file_system
root@192.168.0.1’s password:
root@arunbagul:~#

** Check with mount command whether the file system is mounted or not

root@arunbagul:~# mount | grep sshfs
sshfs#root@192.168.0.1:/var/www on /media/ssh_file_system type fuse (rw,nosuid,nodev,max_read=65536)
root@arunbagul:~#

NOTE – Normal user should be in ‘fuse’ group to mount file system by using sshfs.

root@arunbagul:~# grep fuse /etc/group
fuse:x:106:
root@arunbagul:~#

** How to unmount the directory –

root@arunbagul:~# mount | grep sshfs
sshfs#root@192.168.0.1:/var/www on /media/ssh_file_system type fuse (rw,nosuid,nodev,max_read=65536)
root@arunbagul:~#

root@arunbagul:~# fusermount -u /media/ssh_file_system
root@arunbagul:~#

root@arunbagul:~# mount | grep sshfs
root@arunbagul:~#

done!

command(1) fusermount – mount FUSE filesystems. A virtual FUSE filesystem will be created on the mount point.

Options
-h print help

-V print version

-o opt[,opt…]
mount options

-u unmount

-q quiet

-z lazy unmount (works even if resource is still busy)

command(2) SSHFS – filesystem client based on SSH File Transfer Protocol

usage: sshfs [user@]host:[dir] mountpoint [options]

general options:
-o opt,[opt…]
mount options

-h –help
print help

-V –version
print version

-p PORT equivalent to ‘-o port=PORT’

Cheers,
Arun Bagul

Similar Posts:

Be Sociable, Share!
(0) Comments    Read More   
Post a Comment
Name:
Email:
Website:
Comments:


www.flickr.com
arunbagul's photos More of arunbagul's photos
Get Adobe Flash player
-->