Let’s talk today about SSHFS mount, sometimes you just can’t do NFS or CIFS mount just because ^^
So one solution could be to use SSHFS. I won’t argue about speed, security or benchmarking the thing, I just had no other choice than doing SSHFS so here’s a way to do it with an SSH key and with only a password. (yea that’s a terrible idea but again, sometimes you have no choice)
Obviously if you have things to say about that method, drop a comment I’ll be glad.
I decided to show up only the fstab mount, if you need to do it on the fly then just adapt it 🙂
Both example will be self explanatory for the most, you just have to change the words that I put uppercase.
uid/gid fields are set for the local server’s user (check /etc/passwd), set it to the proper user.
idmap=user is THE trick to keep the correct uid/gid mapping on both servers !
Before to get started, we will be mounting /home/REMOTE_USER/data/ from the remote server in /mnt/data/ on the local server therefore make sure to mkdir the local directory /mnt/data as your mount point.
SSHFS mount in /etc/fstab with a SSH key
Here it’s the IdentifyFile parameter that’s the most important, it must be the SSH private key, don’t forget to put the SSH pub key on the other server.
SSHFS mount in /etc/fstab with a password using sshpass
First install sshpass, on debian (for other OS do a research, it shouldn’t be hard):
This time the important parameter is ssh_command=/home/LOCAL_USER/passwd.sh it’s just a simple script that will do the trick.
Make sure now to edit the file for the ssh_command, here /home/LOCAL_USER/passwd.sh, simply change REMOTE_PASSWORD to the right password.
Make it safer !
And now it’s time to mount:
Probably it won’t all go well, wether you set the wrong password, the wrong key or whatever, if so just add the following options debug,sshfs_debug into your fstab:
Well, not much to add, it’s pretty much useful to use SSHFS but it can be tricky, obviously, do prefer the SSH key method.