Mounting a remote filesystem using sshfs
Mar 16, 2015 · 2 minute read · CommentsDevopsLinuxDevelopment
It seems few people know that you can easily mount a remote filesystem over an ssh connection, using the pretty obviously named tool “sshfs”. It’s pretty buggy on Windows, but it works like a charm on OSX and Linux. You do need a stable network connection to keep the connection working fast though.
Installation
# Homebrew
brew install sshfs
# Ubuntu
sudo apt-get install sshfs
# CentOS
sudo yum install ssfs
Aliases in .bash_profile
I use aliases for most of my ssh connections and sshfs mounts. Combined with using my ssh key (with extra password) this gives me an almost instant login to servers by typing a simple alias for it.
# ~/.bash_profile
#
# Options for ssh and sshfs aliases
# These have been proven to be the best ones for Mac OSX so far
SSHOPTS='-v -4'
SSHFSOPTS='-oauto_cache,reconnect,defer_permissions,noappledouble'
# ssh connection aliases
alias server01="ssh $SSHOPTS karel@server01.example.org"
# sshfs mounts
alias fsserver01="sshfs $SSHFSOPTS -ovolname=server01 \
karel@server01.local:/var/www/vhosts/www.example.org \
$HOME/Projects/www.example.org"
Using an sshfs mount to work
With these aliases in place I would start working like this:
# 1. Mount the remote file system
fsserver01
# 2. Open $HOME/Projects/www.example.org in my local editor
# 3. Login to the server to run my git commands etc:
server01
Remarks
A side note after using these kind of setups for almost 3 years: you need a very fast and reliable internet connection to make this work.
Also funky editors like PHPStorm and Eclipse cannot handle working on a mount like this (they perform a lot of directory and file scanning to discover things), but it works perfectly with Sublime Text 3.