Wednesday, February 19, 2014

Automatic mounting of remote storage via SSHFS on Amazon EC2 instances

In this blog I demonstrate how you can create an Amazon EC2 instance image that will automount a folder on a remote server via SSHFS.
The purpose here is to fire up a EC2 compute server, run a program and save the output from that program on our local compute cluster at the university.

Basically, you just need to a line to /etc/fstab and save the instance as an image (that's what I did).

What you need:

  • An Amazon EC2 instance with sshfs installed.
  • A user with SSH keys properly setup to the remote system (the SSH keys cannot require a passphrase).
Your remote server has a folder that is named remote_folder and your instance has a folder named local_folder. The default username on Amazon is "Ubuntu" for Ubuntu instances, so I'm using this as an example.

sshfs#ubuntu@remoteserver:/home/ubuntu/remote_folder/ /home/ubuntu/local_folder/  fuse    user,delay_connect,_netdev,reconnect,uid=1000,gid=1000,IdentityFile=/home/ubuntu/.ssh/id_rsa,idmap=user,allow_other,workaround=rename  0   0

Everything is one long line that goes into /etc/fstab. The IdentityFile points to your SSH key. You need the "_netdev" keywords to mount the SSHFS folder after network becomes available. The "reconnect" keyword does what it reads, so throw that in as well.
I read a few posts from other people who had difficulties mounting SSHFS properly without the "delay_connect" and "workaround=rename" keywords, so I added those for good measure.

Note that you need the trailing / after the folder names! I won't work without (and I'm talking from bitter experience here).

Furthermore, you want to add the following line to /etc/ssh/ssh_config

ServerAliveInterval 5

This makes SSH send a keep alive signal every 5 seconds so you don't get disconnected due to being idle.

Apart from that I think the above should be self-explanatory (for someone looking for this information).


  1. Thanks for this great post! - This provides good insight. You might also be interested to know more about generating more leads and getting the right intelligence to engage prospects.
    Techno Data Group implements new lead gen ideas and strategies for generating more leads and targeting the right leads and accounts.
    Amazon AWS Users Email & Mailing List

    1. Great Article Cloud Computing Projects

      Networking Projects

      Final Year Projects for CSE

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
    aws training in chennai
    selenium training in chennai

  3. Really nice post.provided a helpful information.I hope that you will post more updates like this. AWS Certification Training

  4. The posttranslational modification of eukaryotic proteins by the addition of isoprenyl lipids at their C-termimi was first observed in the 1970s and 1980s. Since then, more than a hundred proteins have been shown to be modified by C15 farnesyl or C20 geranylgeranyl groups, Peptide C-Terminal Modification

  5. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. Eran Eyal