Categories
Linux shell

SSHFS mount remote file system locally over SSH

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

SSHFS is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

So we have two systems remote.kpsn.pie and local.kpsn.pie. we want to mount directory /home/homer/supercooldir from remote.kpsn.pie as /home/user/remote in local.kpsn.pie and for this discussion on remote system your user is called homer. we will be doing all these commands as user on local system and not root.

This requires SSH key based authentication to be working between the machines prior to this being setup. check out other tutorial on this setup.

so first off you install sshfs on local.kpsn.pie

sudo apt-get install sshfs

Now you need to make the folder in local.kpsn.org.pie where you will be mounting the remote folder so:

mkdir /home/user/remote

now we go about actually mounting the remote directory to the local one we made so:

sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote

What if you have a different port for ssh on remote? well simply use the -p flag, say the port is 12345:

sshfs -p 12345 -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote

to unmount you type:

fusermount -u /home/user/remote

to automagically mount this at startup edit /etc/rc.local

nano /etc/rc.local

and insert this line ABOVE the line saying exit 0

cd /home/user && su -c "/usr/bin/sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote" user

that last “user” is the local machine user. this allows the command to be run as the local machine user so the drive gets mounted properly.

this all is written for ubuntu but should work elsewhere. lemme know of any questions or concerns.

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”]

[/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[jetpack-related-posts]

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Leave a Reply

Your email address will not be published. Required fields are marked *