SSHFS mount remote file system locally over SSH
SSHFS is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.
So we have two systems remote.kpsn.pie and local.kpsn.pie. we want to mount directory /home/homer/supercooldir from remote.kpsn.pie as /home/user/remote in local.kpsn.pie and for this discussion on remote system your user is called homer. we will be doing all these commands as user on local system and not root.
This requires SSH key based authentication to be working between the machines prior to this being setup. check out other tutorial on this setup.
so first off you install sshfs on local.kpsn.pie
sudo apt-get install sshfs
Now you need to make the folder in local.kpsn.org.pie where you will be mounting the remote folder so:
now we go about actually mounting the remote directory to the local one we made so:
sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote
What if you have a different port for ssh on remote? well simply use the -p flag, say the port is 12345:
sshfs -p 12345 -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote
to unmount you type:
fusermount -u /home/user/remote
to automagically mount this at startup edit /etc/rc.local
and insert this line ABOVE the line saying exit 0
cd /home/user && su -c "/usr/bin/sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote" user
that last “user” is the local machine user. this allows the command to be run as the local machine user so the drive gets mounted properly.
this all is written for ubuntu but should work elsewhere. lemme know of any questions or concerns.