﻿{"id":1444,"date":"2016-05-18T15:15:31","date_gmt":"2016-05-18T07:15:31","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1444"},"modified":"2016-05-18T15:15:34","modified_gmt":"2016-05-18T07:15:34","slug":"how-to-mount-a-remote-directory-with-sshfs-on-a-linux","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/1444","title":{"rendered":"How To Mount a Remote Directory With SSHFS on a Linux"},"content":{"rendered":"<p><span class=\"drop_cap\">H<\/span>ow can I mount a remote directory with ssh on a Linux bases system? How do I use SSHFS to mount remote file systems over SSH on a Ubuntu or Debian\/RHEL\/CentOS\/Arch Linux system?\n<span id=\"more-145020\"><\/span>\nSSH is a secure protocol and you can use it to mount a directory on a remote server or local laptop with the help of the SSHF service. With SSHFS you can mount remote server file system to your local development workstation\/laptop powered by Linux.<\/p>\n<h2>More on SSHFS<\/h2>\n<p>sshfs is a filesystem based on the SSH file transfer protocol. It is used on a client system i.e. you need to install sshfs package on your local computer\/laptop powered by CentOS\/RHEL\/Ubuntu\/Debian\/Arch Linux. No need to install anything on server (server1.cyberciti.biz). You only need an openssh server installed on server side. Our sample setup:<\/p>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2016\/05\/071532bG9.jpg\" alt=\"Fig.01: Our sample setup\" width=\"598\" height=\"256\">\n<p class=\"wp-caption-text\">Fig.01: Our sample setup<\/p>\n\n<\/div>\n<h2>Installing SSHFS on a Ubuntu\/Debian\/Mint Linux<\/h2>\n<p>Type the following <a title=\"See Linux\/Unix apt-get command examples for more info\" href=\"http:\/\/www.cyberciti.biz\/tips\/linux-debian-package-management-cheat-sheet.html\">apt-get command<\/a>:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo apt-get install sshfs<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Sample outputs:<\/p>\n<pre>[sudo] password for nixcraft:\nReading package lists... Done\nBuilding dependency tree\nReading state information... Done\nThe following NEW packages will be installed:\n  sshfs\n0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 41.7 kB of archives.\nAfter this operation, 138 kB of additional disk space will be used.\nGet:1 http:\/\/mirror.ox.ac.uk\/sites\/archive.ubuntu.com\/ubuntu\/ trusty\/main sshfs amd64 2.5-1ubuntu1 [41.7 kB]\nFetched 41.7 kB in 1s (27.8 kB\/s)\nSelecting previously unselected package sshfs.\n(Reading database ... 247545 files and directories currently installed.)\nPreparing to unpack ...\/sshfs_2.5-1ubuntu1_amd64.deb ...\nUnpacking sshfs (2.5-1ubuntu1) ...\nProcessing triggers for man-db (2.6.7.1-1ubuntu1) ...\nSetting up sshfs (2.5-1ubuntu1) ...<\/pre>\n<h2>Installing SSHFS on an Arch Linux<\/h2>\n<p>Type the following command:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo pacman -S sshfs fuse<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Installing SSHFS on a RHEL (Red Hat)\/CentOS Linux<\/h2>\n<p>First, <a href=\"http:\/\/www.cyberciti.biz\/faq\/installing-rhel-epel-repo-on-centos-redhat-7-x\/\">turn on EPEL repo and then type<\/a> the following <a title=\"See Linux\/Unix yum command examples for more info\" href=\"http:\/\/www.cyberciti.biz\/faq\/rhel-centos-fedora-linux-yum-command-howto\/\">yum command<\/a> to install FUSE-Filesystem to access remote filesystems via SSH on a CentOS\/RHEL:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo yum install fuse-sshfs<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Sample outputs:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"ini\">Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security\nThis system is receiving updates from RHN Classic or RHN Satellite.\nSetting up Install Process\n0 packages excluded due to repository protections\nResolving Dependencies\n--> Running transaction check\n---> Package fuse-sshfs.x86_64 0:2.4-1.el6 will be installed\n--> Processing Dependency: fuse >= 2.2 for package: fuse-sshfs-2.4-1.el6.x86_64\n--> Running transaction check\n---> Package fuse.x86_64 0:2.8.3-4.el6 will be installed\n--> Finished Dependency Resolution\n\u00a0\nDependencies Resolved\n\u00a0\n=======================================================================================================================\n Package                   Arch                  Version                     Repository                           Size\n=======================================================================================================================\nInstalling:\n fuse-sshfs                x86_64                2.4-1.el6                   epel                                 52 k\nInstalling for dependencies:\n fuse                      x86_64                2.8.3-4.el6                 rhel-x86_64-server-6                 71 k\n\u00a0\nTransaction Summary\n=======================================================================================================================\nInstall       2 Package(s)\n\u00a0\nTotal download size: 123 k\nInstalled size: 115 k\nIs this ok [y\/N]: y\nDownloading Packages:\n(1\/2): fuse-2.8.3-4.el6.x86_64.rpm                                                              |  71 kB     00:00\n(2\/2): fuse-sshfs-2.4-1.el6.x86_64.rpm                                                          |  52 kB     00:00\n-----------------------------------------------------------------------------------------------------------------------\nTotal                                                                                  173 kB\/s | 123 kB     00:00\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n  Installing : fuse-2.8.3-4.el6.x86_64                                                                             1\/2\n  Installing : fuse-sshfs-2.4-1.el6.x86_64                                                                         2\/2\n  Verifying  : fuse-sshfs-2.4-1.el6.x86_64                                                                         1\/2\n  Verifying  : fuse-2.8.3-4.el6.x86_64                                                                             2\/2\n\u00a0\nInstalled:\n  fuse-sshfs.x86_64 0:2.4-1.el6\n\u00a0\nDependency Installed:\n  fuse.x86_64 0:2.8.3-4.el6\n\u00a0\nComplete!<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>How do I mount the remote file system?<\/h2>\n<p>The syntax is<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sshfs user@server \/path\/to\/mountpoint\nsshfs user@server \/path\/to\/mountpoint options<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>First, create a directory using mkdir command:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo mkdir \/mnt\/server1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>I\u2019m going to mount file system using root user and you need to type root password when prompted:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo sshfs root@192.168.1.142:\/ \/mnt\/server1\/\n\u00a0\n##  OR use ssh key based login ##\nsudo sshfs -o IdentityFile=~\/.ssh\/keyfile \/mnt\/server1\/<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Sample outputs:<\/p>\n<pre>Password for root@freebsd10:<\/pre>\n<p>Verify it:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo df -h<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Sample outputs:<\/p>\n<pre>Filesystem              Size  Used Avail Use% Mounted on\n\/dev\/mapper\/wks05-root  487G  114G  350G  25% \/\nnone                    4.1k     0  4.1k   0% \/sys\/fs\/cgroup\nudev                     17G  4.1k   17G   1% \/dev\ntmpfs                   3.4G  1.9M  3.4G   1% \/run\nnone                    5.3M     0  5.3M   0% \/run\/lock\nnone                     17G  160k   17G   1% \/run\/shm\nnone                    105M   50k  105M   1% \/run\/user\n\/dev\/sda1               239M   89M  138M  40% \/boot\nroot@192.168.1.142:\/     20G   12G  6.8G  64% \/mnt\/server1<\/pre>\n<p>To access and\/or to see the remote file system, run:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo -s\ncd \/mnt\/server1\nls -l<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Sample ouputs:<\/p>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2016\/05\/071533rlV.jpg\" alt=\"Fig. 02: sshfs in action\" width=\"598\" height=\"467\">\n<p class=\"wp-caption-text\">Fig. 02: sshfs in action<\/p>\n\n<\/div>\n<h2>Dealing with \u201cPermission denied\u201d error and recommended procedure for mounting the remote directory<\/h2>\n<p>If you get an error that read as cannot access server1: Permission denied, add yourself to a group called fuse:<\/p>\n<pre>$ <strong>sudo gpasswd -a \"$USER\" fuse<\/strong>\n<kbd>Adding user nixcraft to group fuse<\/kbd><\/pre>\n<p>Next, create a mount point inside your own home directory:<\/p>\n<pre>$ <strong>mkdir $HOME\/server1<\/strong>\n$ <strong>ls -ld !$<\/strong>\n<kbd>ls -ld $HOME\/server1\ndrwxrwxr-x 2 nixcraft nixcraft 4096 Mar  8 04:34 \/home\/nixcraft\/server1<\/kbd><\/pre>\n<p>To mount the remote file system, enter:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sshfs -o idmap=user  root@192.168.1.142:\/ $HOME\/server1\ndf\nls -l $HOME\/server1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2016\/05\/071534BCm.jpg\" alt=\"Fig.03: Using sshfs without root access on local laptop\/desktop\" width=\"598\" height=\"625\">\n<p class=\"wp-caption-text\">Fig.03: Using sshfs without root access on local laptop\/desktop<\/p>\n\n<\/div>\n<h2>How do I unmount the remote file system?<\/h2>\n<p>The syntax is:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo umount \/mnt\/server1\n\u00a0\n## OR ##\nfusermount -u \/mnt\/server1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Verify it:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">df -h<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>How can I permanently mount the remote file system by updating \/etc\/fstab?<\/h2>\n<p>Edit the \/etc\/fstab file, enter:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">sudo vi \/etc\/fstat<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The syntax is:<\/p>\n<pre>userNameHere@FQDN_OR_IP_HERE:\/path\/to\/source\/  \/local\/mountdir\/  fuse.sshfs  defaults,_netdev  0  0<\/pre>\n<h3>Examples<\/h3>\n<p>Add the following entry at the bottom of the file:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"ini\">sshfs#root@192.168.1.142:\/ \/mnt\/server1<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Another example with additional options:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"ini\">sshfs#$root@192.168.1.142:\/ \/mnt\/server1 fuse defaults,idmap=user,allow_other,reconnect,_netdev,users,IdentityFile=\/path\/to\/.ssh\/keyfile 0 0<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Recommend option for on-demand mounting if you are using systemd:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"bash\">vivek@server1.cyberciti.biz:\/project\/www\/ \/mnt\/server1  fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=\/home\/vivek\/.ssh\/id_rsa,allow_other,reconnect 0 0<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Save and close the file. Where,<\/p>\n<ol>\n    <li><kbd><strong>root@192.168.1.142<\/strong><\/kbd> : Remote server with sshd<\/li>\n    <li><kbd><strong>fuse<\/strong><\/kbd> : File system type.<\/li>\n    <li><kbd><strong>idmap=user<\/strong><\/kbd> : Only translate UID of connecting user.<\/li>\n    <li><kbd><strong>allow_other<\/strong><\/kbd> : Allow access to other users.<\/li>\n    <li><kbd><strong>reconnect<\/strong><\/kbd> : Reconnect to server.<\/li>\n    <li><kbd><strong>_netdev<\/strong><\/kbd> : The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).<\/li>\n    <li><kbd><strong>users<\/strong><\/kbd> : Allow every user to mount and unmount the filesystem.<\/li>\n    <li><kbd><strong>IdentityFile=\/path\/to\/.ssh\/keyfile<\/strong><\/kbd> \u2013 SSH key file.<\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>How can I mount a remote directory with ssh on a Linux bases system? How do I use SSHFS to mount rem&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[440,136,459,7],"class_list":["post-1444","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-mount","tag-sshfs","tag-ubuntu"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1444"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1444\/revisions"}],"predecessor-version":[{"id":1448,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1444\/revisions\/1448"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}