PDA

View Full Version : Easy sshfs tutorial: mounting remote server folder as local folder - Version 2



Fli
07-20-2017, 12:35 AM
About:

This is newer and simplified version of my first tutorial (https://internetlifeforum.com/linux-forums/1378-easy-sshfs-tutorial-mounting-remote-server-folder-local-folder/).
This tutorial will allow you to install and setup sshfs which will allow your linux machine to access files from other remote (via internet or lan) linux machine the way like it is just another local folder.

Example usage of SSHFS:

example on your home PC you will do command: mplayer /remotestorage/video.mp4
and it will start playing video that is saved on your linux server which can be located anywhere around the globe (have public ip/hostname)

Legend:

client is a home PC or any Linux device that is low on storage and needs to load data from remote location (server)

Tutorial:

on client:

yum install sshfs 2>/dev/null||sudo apt-get install sshfs 2>/dev/null||sudo pacman -S sshfs 2>/dev/null

ssh-copy-id -p sshporthere root@serverip
(if no key yet, try "ssh-keygen" command, enter no password and then retry ssh-copy-id.)
root username is optional and sshporthere is usually 22

once connected again using command: ssh -p sshporthere root@serverip
without password prompt, then execute on the server:

yum install sshfs 2>/dev/null||sudo apt-get install sshfs 2>/dev/null||sudo pacman -S sshfs --no-confirm -v 2>/dev/null

mkdir -p /data/storage

then exit back to client terminal by command: exit

create directory that will be used as an alias of the remote server storage:

mkdir /remotestorage

connect server by executing following on the client:


sshfs username@serverip:/data/storage /remotestorage -o idmap=user,reconnect,ServerAliveInterval=15,Server AliveCountMax=3,port=22
(personal notes: removed deprecated ,nonempty, parameter)

If error, google that error. If no error, test new remote sshfs storage system by creating new file:

echo content > /remotestorage/file;cat /remotestorage/file

it should return: content

you can execute: ssh serverip -p sshport cat /data/storage/file

and it should also return "content" which means that remote and local are synchronized.

Make the SSHFS volume auto mount @boot time on the client by adding following line into /etc/fstab

user@serverip:/data/storage /remotestorage fuse.sshfs defaults,_netdev 0 0

When you restart the computer, your remote storage should be there. If problem, try to google or comment there. Thank you and enjoy.