Sometimes when I’m in a conference of in a meeting. I need some files that is on my PC but not on my laptop to run my demo program. There’s no way I could run back home or to my lab to grab them. And the only thing I have on my PC running(running Linux) at the time is a SSH server. Sh*t, setting up a http server to transport files takes minutes even with nodejs and http-server. And sometimes I need bidirectional IO… I have a perfect solution for that.
SSHFS is a program/command that allows you to mount a remote system’s directory like a local disk. The only requirement of the remote system is that a SSH server is running on it. On Ubuntu/Debian, sshfs can be intalled via
sudo apt-get install sshfs
On Arch based system. You want to use
pacman for this.
sudo pacman -S sshfs
Once mounted. The directory acted as a normal directory. You can do a
ls on it. Read and write from it, etc… The data is transferred instantaneously. There are no caching and buffering going on. Well… due to that there are no caching. The file accessing speed is limited to your network speed. Be aware of this.
Once installed. You are good
Mounting a remote directory
Now, to mount a remote directory. Use the
sshfs command. The command works like the
mount command we are so used to. For example. To mount the directory
~/Documents of user
marty on a box at 192.168.0.2 to
~/RemoteDir. The Following command is used.
sshfs email@example.com:~/Documents ~/RemoteDir
ssh you cad add a
-p parameter to specify the port your SSH server is runnint at.
There are a lot more you can do with this command described on ArchWiki. Have a look if you are interested.
To unmount a directory mounted by sshfs:
fusermount -u /path/to/your/sshfs/mount
fusermount -u ~/RemoteDir
SSHFS got stuck
If you have unstable connection. SSHFS might got stuck. Any file inside SSHFS cannot be read or written. If that happens. Unmount the directory then remount it again. Then your good to go.
Have fun developing 😀