projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

SSHFS the SSH FileSystem

Linux is all about files, files and a tool for a job thats what you are told when you read about this OS. Very early on you will also learn Linux is about connectivity and there are many ways in which connectivity aids you on a Linux PC we can mount remote Windows shares, connect to remote desktops, attach to internet servers it’s SSH however which will be the tool which you find is a regular tool in the Linux toolbox.

So why use SSHfs instead of SMB or NFS to mount remote filesystems locally? the main reason i’d suggest is because SSH encrypts its connections. Setup properly as part of FSTAB the remote file systems should be pretty transparent to the user and SSH is from experience more stable over a WAN connection.

The Ubuntu help community has a good writeup on SSHFS

https://help.ubuntu.com/community/SSHFS

Installation and Setup

Simply install the following packagesshfs, then add yourself to the fuse group:

sudo gpasswd -a $USER fuse

Alternatively, GNOME users can go to System -> Administration -> Users and Groups -> (your user) -> Properties -> User Privileges, then tick the following option:

Allow use of fuse filesystems like LTSP Thin Client blockdevices

Adding yourself to the fuse group lets you use the fusermount command, which is needed by the FUSE userland filesystem utility.

Once you have added yourself to the fuse group, you should log out and log back in again for the change to take effect.

Command-line Usage

Now, assuming that you have an SSH server running on a remote machine, simply run the SSHFS command to mount the remote directory. In this example, the remote directory is /projects on remote host far. The local mount point is ~/far_projects.

mkdir ~/far_projects
sshfs -o idmap=user $USER@far:/projects ~/far_projects

To unmount,

fusermount -u ~/far_projects

To add it to your /etc/fstab,

sshfs#$USER@far:/projects /home/$USER/far_projects fuse defaults,idmap=user 0 0

Note that you have to change $USER to your login name when editing fstab, but it is not necessary when typing commands (the shell does it for you in that case).

One thing to be aware of is that your UID (User ID, the unique number of your user on a system) is not necessarily the same on the two hosts. When you ls -l, the user name associated with each file is printed in the third column. However, in the filesystem, only UIDs are stored, and lssimply looks up the UID and finds the user name associated with it. In Unix, UIDs are what matter, not the user names. So if you’re 1000 on the local host and 1003 on the remote host, the sshfs mounted directory would show a different user name for your files. This is not a problem, though, because the ssh server on the remote machine is what is actually reading and writing files. So even though it shows up in ls -l as a different UID, any changes will be done through the ssh server on the remote host, which will use the correct UID for the remote machine. Problems may arise if you attempt to use a program that looks at UIDs of files (e.g. ls prints the wrong user name).

So there we have it, you can have systems remotely mounted securely using an encrypted file system as well so the whole lot is secure..

Advertisements

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

%d bloggers like this: