{"id":11206,"date":"2024-04-24T15:50:14","date_gmt":"2024-04-24T14:50:14","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=11206"},"modified":"2024-04-24T15:50:15","modified_gmt":"2024-04-24T14:50:15","slug":"mounting-a-remote-file-system-with-sshfs","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2024\/04\/mounting-a-remote-file-system-with-sshfs\/","title":{"rendered":"Mounting a remote file system with SSHFS"},"content":{"rendered":"\n<p>If you&#8217;re working with data stored on a remote server, you might not want to (or even have the space to) copy data to your local file system when you work on it. Instead, we can use SSHFS to mount a remote file system via SSH, allowing us to read and write data on the remote file system without manually copying files.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>First, if you haven&#8217;t already done so, install sshfs. It&#8217;s available for most linux distributions through your package manager (e.g. apt; dnf).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt install sshfs<\/pre>\n\n\n\n<p>Next, you&#8217;ll need a local directory to mount the remote directory. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mkdir \/mnt\/remote<\/pre>\n\n\n\n<p>The \/mnt directory already exists for this purpose, but there&#8217;s no reason you have to use it. For example, if you want to allow a non-root user to use sshfs (more on this later) without write permissions in \/mnt, they will need to create their own mount point.<\/p>\n\n\n\n<p>To mount a remote directory, simply run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo sshfs username@remotehost:\/remote \/mnt\/remote<\/pre>\n\n\n\n<p>To unmount the remote filesystem:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo fusermount3 -u \/mnt\/remote<\/pre>\n\n\n\n<p>By default, sshfs can only be run as root. This complicates matters, as only the root user will be able to write the mounted file system. To get around this, we can tell sshfs to allow other users to access the mount with suitable permissions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo sshfs -o allow_other,default_permissions username@remotehost:\/remote \/mnt\/remote<\/pre>\n\n\n\n<p>You&#8217;ll also need to uncomment &#8216;user_allow_other&#8217; in <code>\/etc\/fuse.conf<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Set the maximum number of FUSE mounts allowed to non-root users.                       \n# The default is 1000.                                                                   \n#                                                                                        \n#mount_max = 1000                                                                        \n\n# Allow non-root users to specify the 'allow_other' or 'allow_root'                      \n# mount options.                                                                         \n#                                                                                        \nuser_allow_other <\/pre>\n\n\n\n<p>Finally, you may need to add read permissions for non-root users:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chmod a+r \/etc\/fuse.conf<\/pre>\n\n\n\n<p>With that, you should be able to mount a remote file system and make it accessible to any user (including your own non-root account). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re working with data stored on a remote server, you might not want to (or even have the space to) copy data to your local file system when you work on it. Instead, we can use SSHFS to mount a remote file system via SSH, allowing us to read and write data on the [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[348,14,588,15],"tags":[247,768,767],"ppma_author":[498],"class_list":["post-11206","post","type-post","status-publish","format-standard","hentry","category-bash","category-howto","category-linux-gnu-linux","category-technical","tag-linux","tag-ssh","tag-sshfs"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":498,"user_id":47,"is_guest":0,"slug":"fergus","display_name":"Fergus Boyles","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/ba8c419ba77128aad589b66ba7ee13da74f4ce2d3108fd724ddcefa200b51c7b?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=11206"}],"version-history":[{"count":3,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11206\/revisions"}],"predecessor-version":[{"id":11289,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/11206\/revisions\/11289"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=11206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=11206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=11206"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=11206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}