Sometimes you just need to copy some files between two computers, you can do that with scp, sftp or rsync. But some of those times you also need to navigate the remote folders and those three options are too cumbersome. A quick&dirty solution is to mount a remote folder with sshfs.
You could export that folder with NFS, Samba or some other network filesystem, but you’ll need to deal with config files, firewalls,… But you surely have already an ssh access to your remote system. If you don’t, you shouldn’t been here.. I think xD
Install required package
I’m assuming that on origin (the ‘server’) you already have a running ssh access. On destination (the ‘client’) you need to install a program named sshfs.
Binaries
On debian derivatives (ubuntu, mint, devuan), run:
sudo apt-get install sshfs
On centos, fedora and other distros working with yum:
sudo yum install sshfs
Compiling
On Gentoo Linux run:
emerge -av net-fs/sshfs
On FreeBSD install the port with:
# cd /usr/ports/sysutils/fusefs-sshfs/ # make install clean
Manually dowloading and compiling
Go to https://github.com/libfuse/sshfs to download and follow the instructions on the readme.
Mount a remote folder with sshfs
With the sshfs executable, to mount any remote folder is as easy as run:
sshfs user@host:/path/to/remote/folder /path/to/mountpoint/
Typing passwords is boring…
I’m know, but unfortunately, sshfs doesn’t include the -i
switch to load a private key file. Fortunately sshfs include the -o
switch to call most (if not all) of the ssh options.
The option we need is IdentityFile
. Take a look on my screenshot, for some reason I didn’t use the standard name id_rsa/id_rsa.pub when I’ve generated my keys. I don’t remember that reason.
Making permanent
This would last until you reboot your system. To make it permanent you need to add to your /etc/fstab the following line:
user@host:/path/to/remote/ /path/to/mountpoint fuse.sshfs defaults 0 0
Alternatives to sshfs
You can do the same, but the remote system wouldn’t be available system wide (say, apache couldn’t use a remote folder) with mc, the midnight commander, pressing F9 and choosing Sftp link:
On the prompt write the remote address following this format sftp://[user@]machine:[port]/[remote-dir]
, then write your password and you are in.
On the graphic desktop side, several file managers support it. I didn’t use the big ones (like gnome, kde, etc) for a long time, I don’t even know the program names anymore, but I know they support ssh. This is pcmanFm from LXDE, use an address in the same format as with midnight commander, for example:
I don’t know the name of the package that do this magic, but if you are using linux in a desktop you probably already installed.