CentOS : Mount SSHFS files system on boot

Well got myself a nice shiny VPS from Rackburst and currently in the process of setting it up to run my websites.

As part of the VPS package you get additional remote storage which is setup via SSHFS, which is great as the data stored there doesn’t get deleted if you re-built your VPS however the downside to this is when you restart your server the storage isn’t re-mounted on boot given you need to provide your SSHFS account password.

After a quick search on my friend Google found a very useful post over on Dark Launch on a script to use at boot.

This is the full process I followed including adding the script for it to run at boot:

You will need to install SSHFS and FUSE, on CentOS you need to enable the Epel repo instructions can be found here: http://www.centosblog.com/enable-epel-repo-on-centos-5-and-centos-6/

Initial command:

In the above command replace the following:

  • mypassword – password for your SSHFS account
  • myuser – username for your SSHFS server
  • ftp.mysite.com  – IP or hostname of you SSHFS fileserver
  • ~/mounts/mysite – Folder to mount the filesystem to, this folder must exist before attempting to mount.

First your need to create the mount script and allow execution:

Next add the above command to the script file:

Yes echo is there twice for a reason Big Smile

We now need to add the script to the start up by doing the following:

You can now test the script by either running it or restarting the server.

We can then check the filesystem is now mounted by running the following:

Please note the process may vary on other Linux flavours.