Introduction to SSHFS – the *best* way do transfer files between your PC and you when you are outside and in emergency

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

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 apt

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 marty@192.168.0.2:~/Documents ~/RemoteDir

Just like 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.

Unmounting directory

To unmount a directory mounted by sshfs:

fusermount -u /path/to/your/sshfs/mount

For example:

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 😀

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: