Linux : Mounting A Remote Network Folder Locally


SSHFS and FUSE To Mount Remote Network Resources

UPDATE (2014.04.09): I may have been premature with the startup script mentioned below.  This doesn’t seem to work.  I am assuming the failure is because my profile isn’t loaded at the time the script is run or my account isn’t allowed to to run scripts using @reboot in a cron config.  Whatever the case, I have found a configuration that works.  I put the startup script call in my ~/.bashrc file and it works as intended.  Here’s the line I added after my environmental declarations (near the bottom):

~/startup.sh

Everything else worked pretty well.  I am getting the following message when I open a terminal and I will need to do more research as to how to resolve this:

fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option

</UPDATE> At work, I have a network homedrive for my Linux systems that I only have access network-drive-connectedto once logged into one of my systems.  Once I am in one system, it’s easy for me to move scripts and files around but I have always struggled with the overt disconnection between my local workstation andy my network.  My requirements were straightforward: Easy to configure locally, no network/remote configuration required, maintains solid security, and scriptable. Today, I made a push to get some level of resolution to this issue and I was finally successful using sshfs and FUSE.  While not strictly work related, this will be a huge improvement for my BeagleBone Black projects as well.  It was much easier than I thought it would be.  Let’s say I want to mount the remote home drive from my BeagleBone (hostname: ‘trisket’, user: ‘dave’). NOTE: These instructions assume Ubuntu, but I’m sure the process is the same for other distros

1. Install (if it’s not already installed) ‘sshfs’ on my client

sudo apt-get install sshfs

2. Verify that my user account is in the fuse group.

groups dave

which returns:

dave adm dialout cdrom sudo dip plugdev fuse lpadmin sambashare

If not, add user:

sudo adduser dave fuse

3.  Verify ownership of /dev/fuse and make sure it’s root:fuse.  This is important!

ls -la /dev/fuse

yielded:

crw-rw---- 1 root root 10, 229 Apr  3 09:12 /dev/fuse

I fixed this with:

sudo chown root:fuse /dev/fuse

4.  Create a mount point:  (I wanted this in my home folder)

mkdir ~/bbb

5: Mount the remote resource:  sshfs remoteuser@remotehost:/remote/resource /local/resource

sshfs dave@trisket:/home/dave ~/bbb

Success!  Now I have the remote BBB home folder mounted on my local workstation. This worked amazingly well and it was very easy to to add others.  In retrospect, I think I will centralize the mount points that I bind to much like the mount folder.  I am keeping these separate from /media or /mnt for my own sanity. Finally, a quick word on persistence.  After I mounted the drive, I logged out and back in and the mount was still there.  However, after a reboot, it disappeared.  So, as I have mentioned in previous posts for my BeagleBone Black initial configuration, I created a startup script that runs on reboot.  There’s lots of ways to do this but this is my method which helps me keep everything organized and within scope. First I added the mount line to my ~/startup.sh script:

#! /bin/bash

~/getIP.py
~/updateGateway.sh
sshfs dave@trisket:/home/dave ~/bbb

Because I have this already to run on reboot/startup, I don’t have to do anything else.  However, if you are setting this up for the first time, you can have the cron service run this file for you.  I have other posts that go into more detail but you can simply add one entry in your crontab to get this done:

crontab -e

then add the following line:

@reboot /home/dave/startup.sh

Just make sure you change the path to where your startup.sh script is saved.  Also, don’t forget to make your startup script executable:

chmod +x startup.sh

Overall, this was a very easy feature add to my local client configuration and the value is huge, especially at work.  I hope this helps someone and if you have any questions, feel free to post comments.

Advertisements