On ZDNet: 10 most annoying programs

Use shfs to mount remote directories via ssh

Tags: Vincent Danen, kernel, file system, SSH, kernel module, Linux Tips Newsletter

  • Save
  • Print
  • 5

Takeaway: Vincent Danen describes shfs, which allows you to mount remote directories that look like local file systems, without the hassle of VPN connections.

The ability to export remote file systems is extremely useful, which is why programs like NFS and Samba are so popular. Unfortunately, both are typically tied to a local network which limits their usage somewhat. An ideal file system would allow for encrypted connections to a remote site, without resulting in complicated VPN connections.

This is exactly what shfs, the SHell File System, does. It allows for the mounting of remote directories via ssh by using a kernel module (like smbfs) and a user-space tool, like mount. To get started, you can download shfs from http://shfs.sourceforge.net/; the latest version as of this writing is 0.35. Before starting, be sure you have the kernel source for your currently running kernel available and be sure the C compiler you have is the exact version that was used to compile the kernel.

$ mv shfs-0.35.tar.gz /usr/local/src
$ cd /usr/local/src
$ tar xvzf shfs-0.35.tar.gz
$ cd shfs-0.35
$ make
$ sudo make install

The example above will compile the kernel module for your kernel (shfs supports both the 2.4 and 2.6 kernels) and will also compile the shfsmount utility.

If you are using gcc4, you will need to download and apply this patch to the shfs source for it to compile properly:

http://atrey.karlin.mff.cuni.cz/~qiq/src/shfs/shfs-0.35/gcc4-compilefix.patch.

Once you have shfs installed, load the kernel module and mount your first remote file system:

# modprobe shfs
# shfsmount user@remote /mnt/user

This will mount the home directory of user@remote in the directory /mnt/user. You can also use mount itself:

# mount -t shfs user@remote:/data /data

This would allow you to automount certain directories at boot by adding entries to /etc/fstab. Of course, you would want to use ssh keys with that because on every mount, you'll be asked for a passphrase or password.

As you can see, shfs is extremely easy to use and versatile. It allows you to mount a remote drive at the office that your desktop at home recognizes as a local file system, but without the hassles of making anything more than ssh available on the remote system.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

  • Save
  • Print
  • 5

Print/View all Posts Comments on this article

SHFS installationapotheon  | 06/20/06
Simplicity or justified learningalanyuu  | 06/21/06
Um, dude.apotheon  | 06/21/06
there are two distros where it's build from source onlyJaqui  | 06/21/06
my point exactlyapotheon  | 06/21/06
adding a package managerJaqui  | 06/21/06
or . . .apotheon  | 06/22/06
Good point, if slightly angry ;)olegkio  | 06/26/06
no no no no no noJaqui  | 06/27/06
FreeBSDVetch_101  | 06/28/06
CheersVetch_101  | 06/28/06
ah aimz ta pleezeapotheon  | 06/28/06
Thank you for the article [nt]olegkio  | 06/26/06
shfs doesn't supports seeking in file ?romco  | 07/10/06
What does this meantrwagner1@...  | 10/19/06

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here