CSCI 251 Systems and Networks

Lab 8  Sharing files using sshfs

Wednesday March 17, 2010


Connecting two machines via the network and mounting a directory from one machine into the file system of the other can be quite convenient in such areas as
Linux is now widely used in the embedded systems world (for example, see In such a situation, a high-powered, resource-rich workstation can have a directory mounted on the embedded system. With cross development tools on the workstation, one can then develop and test code for the embedded system, from the workstation. Note that this is quite distinct from an ssh or telnet connection. Alternatives for mounting a file directory node from one machine into the root file system of another include (among others)
The latter is considered more secure and is also simpler to deploy. We do not have an embedded system to explore this topic, but we can emulate the behavior by establishing such a connection using these two machines:
or these two
In either case we'll mount a directory from the other machine into your vbx file system. It might be convenient to do it the other way around, but deploying sshfs requires root privileges. Not having root privileges on either OS251 or CSCIUN1 means that you are only able to install and deploy sshfs on your vbx. Obviously this would not be a constraint on a system (such as your home machine) where you are the system administrator.

Note: Task #5 is somewhat separate material. It introduces the tar command and several compression utilities. Many of you are already familiar with these topics, in which case this would be a review.

Task #1 - Install any needed packages on your vbx (Keep a record of your activities.)  

You likely already have openssh-server on your vbx. If not, you will need to install it. You will also need to install sshfs, whose dependencies will then trigger installation of some other packages. Use synaptic or aptitude to perform these installations.

Only users in the group 'fuse' are allowed to mount directories using sshfs. Check if you are already a member of the group 'fuse'. You can check your group membership using the command 'id'. Use the command 'usermod' to add yourself to the 'fuse' group. Adding a user to a group can only be done by the root user.

You have to logout and log in again for the changes to take effect.

Task #2 - Attempt to establish the sshfs mount on your vbx (Keep a record of your activities.)

Ensure that ssh is working by connecting to your OS251 from the vbx i.e.

ssh username@OS251-IP-Address
e.g. ssh smithw@

When successful, exit from the connection.

You will be mounting your OS251 home directory within your vbx, so make a directory for the mount point e.g.

mkdir os251/

within your home directory.

Next, as ordinaray user, attempt to mount your OS251 home directory on this newly created mount point.

sshfs os251-username@OS251-IP-Address:/home/os251-username os251/
e.g. sshfs smithw@ os251/

Use the command 'mount' to see what is mounted currently.

Finally, check the contents of os251/ by entering

ls -l os251/

Do the contents match those of your OS251 home directory? If not, ask the instructor for help. When all is OK, unmount your OS251 home directory (still as root) via

fusermount -u os251/

Task #3 - Modify /etc/fstab to ease the mount process (Keep a record of your activities.)

Rather than typing the above long command everytime we want to do the sshfs mount, we can append a line to /etc/fstab.  As root, make a backup of the /etc/fstab (as //etc/fstab.orig) and append a line like the following to /etc/fstab:

sshfs#os251-username@OS251-IP-Address:/home/os251-username /home/vbx-username/os251 fuse user 0 0
e.g. sshfs#smithw@ /home/wsmith/os251 fuse user 0 0

Subsequently, we should be able (as the user) to mount the directory via the traditional command

mount os251

Then check the contents of os251/ by entering

ls -l os251

Do the contents match those of your OS251 home directory? If not, ask the instructor for help. When all is OK, unmount your OS251 home directory (still as user) using

fusermount -u os251

Task #4 - Try with your CSCIUN1 home directory

Repeat Task #2 and Task #3 using your csciun1 home directory instead of your OS251 home directory. Note that your csciun1 home directory is not of the style /home/csciun1-username. To see what it is, you can ssh into your csciun1 account and enter


the 'present working directory' command.

Task #5 - Introduction to 'tar' (Keep a record of your activities.)

The venerable 'tar' command remains a useful workhorse, allowing us to wrap up files (e.g. directory hierarchies) in a single archive file. Further, it plays nicely with compression applications such as

bzip2, bunzip2
gzip, gunzip

The 'tar' manpage gives an account of its various capabilities. Here we'll focus on the three most commonly used operations:

5.1 Creating a new tar archive
(Keep a record of your activities.)

Pick several files from your home directory to archive. Let's say their names are file1.odt , file2.asm, file3.c. To create an archive, we can enter

tar cvf my_archive.tar file1.odt file2.asm file3.c

where the 3 concatenated options mean the following
This would creat an archive named my_archive.tar.

We can also compress as we archive
tar cvzf my_archive.tar.gz file1.odt file2.asm file3.c
tar cvzf my_archive.tgz file1.odt file2.asm file3.c
tar cvjf my_archive.tar.bz2 file1.odt file2.asm file3.c

Compressing as we archive is not supported by all Unix variants, and may require two successive steps

5.2 Listing the contents of an existing tar archive (Keep a record of your activities.)

Let's use the archives built in Task 4.1 to list the files they contain. Try these commands

5.3 Extracting an existing tar archive or from an existing tar archive (Keep a record of your activities.)

To see how to extract an entire archive to get the original system organization back, let's just extract the archives created in Task 5.1. To avoid just writing over the original files,
The extract (and uncompress, if appropriate) commands are
Although we'll not discuss it here, it is also possible to extract individual files from the archive file rather than the whole archive.

5.4 An example application (Keep a record of your activities.)

We could, for example, develop a web site on our machine to be exported to a web hosting service. Some such services also provide their clients (that's us) with a shell account. So working on our home machine we develop a vast web site with various subdirectories, but all rooted at the top directory node 'my_web_site. We then
tar cvjf my_web_site.tar.bz2 my_web_site
tar xvjf my_web_site.tar.bz2

Simulate the above using

Task #6 - To receive credit for this lab

Submit your report for this assignment to the instructor by email per the following specification:

Report Specification
e.g. jayeward-lab8.txt
cat jayeward-lab8.txt

To receive credit, the properly configured email (with attachment) must be received by 8 AM, Monday March 22, 2010.