How To Mount a Remote Directory With SSHFS on a Linux

How 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?

SSH 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. [donotprint]
Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements sshfs
Est. reading time 10m

More on SSHFS

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 ( You only need an openssh server installed on server side. Our sample setup:

Fig.01: Our sample setup

Fig.01: Our sample setup

Installing SSHFS on a Ubuntu/Debian/Mint Linux

Type the following apt-get command:

apt-get update && apt-get upgrade
sudo apt-get install sshfs

Sample outputs:

[sudo] password for nixcraft: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 41.7 kB of archives.
After this operation, 138 kB of additional disk space will be used.
Get:1 trusty/main sshfs amd64 2.5-1ubuntu1 [41.7 kB]
Fetched 41.7 kB in 1s (27.8 kB/s)
Selecting previously unselected package sshfs.
(Reading database ... 247545 files and directories currently installed.)
Preparing to unpack .../sshfs_2.5-1ubuntu1_amd64.deb ...
Unpacking sshfs (2.5-1ubuntu1) ...
Processing triggers for man-db ( ...
Setting up sshfs (2.5-1ubuntu1) ...

Installing SSHFS on an Arch Linux

Type the following command:

sudo pacman -S sshfs fuse

Make sure you add user named vivek to fuse group:
## [ create fuse group if does not exist as per your distro ] ##
$ sudo groupadd fuse
$ sudo usermod -a -G fuse vivek

Installing SSHFS on a RHEL (Red Hat)/CentOS Linux

First, turn on EPEL repo and then type the following yum command to install FUSE-Filesystem to access remote filesystems via SSH on a CentOS/RHEL:

sudo yum update
sudo yum install fuse-sshfs

Sample outputs:

Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
0 packages excluded due to repository protections
Resolving Dependencies
--> Running transaction check
---> Package fuse-sshfs.x86_64 0:2.4-1.el6 will be installed
--> Processing Dependency: fuse >= 2.2 for package: fuse-sshfs-2.4-1.el6.x86_64
--> Running transaction check
---> Package fuse.x86_64 0:2.8.3-4.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
 Package                   Arch                  Version                     Repository                           Size
 fuse-sshfs                x86_64                2.4-1.el6                   epel                                 52 k
Installing for dependencies:
 fuse                      x86_64                2.8.3-4.el6                 rhel-x86_64-server-6                 71 k
Transaction Summary
Install       2 Package(s)
Total download size: 123 k
Installed size: 115 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): fuse-2.8.3-4.el6.x86_64.rpm                                                              |  71 kB     00:00     
(2/2): fuse-sshfs-2.4-1.el6.x86_64.rpm                                                          |  52 kB     00:00     
Total                                                                                  173 kB/s | 123 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : fuse-2.8.3-4.el6.x86_64                                                                             1/2 
  Installing : fuse-sshfs-2.4-1.el6.x86_64                                                                         2/2 
  Verifying  : fuse-sshfs-2.4-1.el6.x86_64                                                                         1/2 
  Verifying  : fuse-2.8.3-4.el6.x86_64                                                                             2/2 
  fuse-sshfs.x86_64 0:2.4-1.el6                                                                                        
Dependency Installed:
  fuse.x86_64 0:2.8.3-4.el6                                                                                            

How do I mount the remote file system?

The syntax is

sshfs user@server /path/to/mountpoint
sshfs user@server /path/to/mountpoint options

First, create a directory using mkdir command:

sudo mkdir /mnt/server1

I’m going to mount file system using root user and you need to type root password when prompted:

sudo sshfs root@ /mnt/server1/
##  OR use ssh key based login ##
sudo sshfs -o IdentityFile=~/.ssh/keyfile /mnt/server1/

Sample outputs:

Password for root@freebsd10:

Verify it:

sudo df -h

Sample outputs:

Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/wks05-root  487G  114G  350G  25% /
none                    4.1k     0  4.1k   0% /sys/fs/cgroup
udev                     17G  4.1k   17G   1% /dev
tmpfs                   3.4G  1.9M  3.4G   1% /run
none                    5.3M     0  5.3M   0% /run/lock
none                     17G  160k   17G   1% /run/shm
none                    105M   50k  105M   1% /run/user
/dev/sda1               239M   89M  138M  40% /boot
root@     20G   12G  6.8G  64% /mnt/server1

To access and/or to see the remote file system, run:

sudo -s
cd /mnt/server1
ls -l

Sample ouputs:

Fig. 02: sshfs in action

Fig. 02: sshfs in action

Dealing with “Permission denied” error and recommended procedure for mounting the remote directory

If you get an error that read as cannot access server1: Permission denied, add yourself to a group called fuse:

$ sudo gpasswd -a "$USER" fuse
Adding user nixcraft to group fuse

Next, create a mount point inside your own home directory:

$ mkdir $HOME/server1
$ ls -ld !$
ls -ld $HOME/server1
drwxrwxr-x 2 nixcraft nixcraft 4096 Mar  8 04:34 /home/nixcraft/server1

To mount the remote file system, enter:

sshfs -o idmap=user  root@ $HOME/server1
ls -l $HOME/server1
Fig.03: Using sshfs without root access on local laptop/desktop

Fig.03: Using sshfs without root access on local laptop/desktop

How do I unmount the remote file system?

The syntax is:

sudo umount /mnt/server1
## OR ##
fusermount -u /mnt/server1

Verify it:

df -h

How can I permanently mount the remote file system by updating /etc/fstab?

For persistent mounts, you must create ssh keys based login
$ ssh-keygen -t rsa
$ ssh-copy-id -i ~/.ssh/

Now, edit the /etc/fstab file, enter:

sudo vi /etc/fstab

The syntax is:

userNameHere@FQDN_OR_IP_HERE:/path/to/source/  /local/mountdir/  fuse.sshfs  defaults,_netdev  0  0


Add the following entry at the bottom of the file:

sshfs#root@ /mnt/server1

Another example with additional options:

sshfs#$root@ /mnt/server1 fuse defaults,idmap=user,allow_other,reconnect,_netdev,users,IdentityFile=/path/to/.ssh/keyfile 0 0

Recommend option for on-demand mounting if you are using systemd: /mnt/server1  fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/vivek/.ssh/id_rsa,allow_other,reconnect 0 0

Save and close the file. Where,

  1. root@ : Remote server with sshd
  2. fuse : File system type.
  3. idmap=user : Only translate UID of connecting user.
  4. allow_other : Allow access to other users.
  5. reconnect : Reconnect to server.
  6. _netdev : 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).
  7. users : Allow every user to mount and unmount the filesystem.
  8. IdentityFile=/path/to/.ssh/keyfile – SSH key file.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 23 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
23 comments… add one
  • Jouni "rautamiekka" Järvinen Mar 8, 2015 @ 0:26

    Word of warning: SSHFS is even slower than FTP since §sshd§ has to {en|de}crypt everything, it’s also slow doing it, which also makes SFTP Clients slow to like 100-300KB/s speed. SSHFS is a nice thing to transparently move data, but be prepared for ultra-slow transmission even on powerful CPU.

    • Matthew Lenz Mar 9, 2015 @ 16:35


      • Jouni "rautamiekka" Järvinen Mar 9, 2015 @ 17:12

        Oh yes.

        • Tim Peoples Mar 17, 2015 @ 15:47

          That’s odd. I just transfered 20MB (via dd) over an sshfs connection on a 10Mb/s line and it transfered at 1.1MB/s (note bits vs bytes). This speed is about what I would expect even without any encryption overhead… so, I’m with Matthew and say, “No.” There is no significant performance loss due to ssh encryption (at least not on relatively modern hardware).

          • Jouni "rautamiekka" Järvinen Mar 18, 2015 @ 16:47

            What hardware ?

            • Michal Dec 20, 2016 @ 10:59

              What a question?
              Here you can learn something from guys they know what are they doing!
              “The advantages of sshfs over NFS and Samba are a repsonsiveness much closer to local file systems than either of the common systems and somewhat faster transfer speeds (your mileage may vary). Also it has (at least for me) proven very stable with no outtages yet. The simplicity of sshfs setup can also be an advantage if you do not actually have a use for Samba’s bewildering array of configuration options. If you know how to use SSH, you know how to use sshfs. “

    • Michal Dec 20, 2016 @ 10:53

      Before you make a statement like this, do your research, do your homework, possibly try yourself. Do not just throw around whatever you thing or hear from experts on the internet!!!
      Damn, I am sick of these experts all around the web!

      • Jouni "rautamiekka" Jrvinen Aug 16, 2017 @ 9:53

        It’s from years of personal experience !

  • Cesar Mar 8, 2015 @ 3:48

    Great article!, I just have a question, how to add the port in the /etc/fstab file if external host has ssh listening on a non standard port?


    • 🐧 nixCraft Mar 8, 2015 @ 4:14

      Pass it as port=1234 in /etc/fstab:

      sshfs#$root@ /mnt/server1 fuse defaults,idmap=user,port=1234,allow_other,reconnect,_netdev,users,IdentityFile=/path/to/.ssh/keyfile 0 0

      Or type it at command prompt:

      sshfs -o idmap=user,port=1234 user@host:/path /mnt/local
  • black_rabbit Mar 8, 2015 @ 23:22

    sshfs#$root@ /mnt/server1 fuse defaults,idmap=user,allow_other,reconnect,_netdev,users,IdentityFile=/path/to/.ssh/keyfile 0 0

    Really?! root + user + allow_other? Facepalm… I know it’s just an example, but com’on… Noobs are copying from this kind of sites!

    • 🐧 nixCraft Mar 9, 2015 @ 7:18

      The post has been updated to include non-root /etc/fstab entry. I appreciate your feedback and time.

  • nws Mar 12, 2015 @ 6:37

    Works great for mac as well:

    Download and install OSXFuse from here:
    Download and install SSHFS as well (also here
    Launch terminal
    $sshfs -p2222 @:
    (note -p2222 for the port rather than -port=2222 on a mac)

    This works great for mounting a remote log directory and then running a bunch of tails in different terminal tabs.

    • nws Mar 12, 2015 @ 6:41

      Apologies, looks like the example got a little messed up

      $sshfs -p2222 user@host:remote_path local_path

  • simon Jun 17, 2015 @ 18:07

    Great tutorial and I got it working for cpanel backups.
    The only issue I had was that the datacentre see the traffic as going out AND then reading back IN to the server, so it doubled my bandwidth usage.
    The advantages of using ssh was brilliant though as I could send cpanel backups directly to the backup server via SSH and not have a problem with local space.

  • luli Jul 24, 2015 @ 11:43

    l have one question ?
    l have setup 2 server , server1 and server2
    l am trying to share hdd from server1 to server2
    where l should added fstab , in server1 or server2

    bacuase really l dont understand

    • Zero State Mar 20, 2016 @ 11:45

      Hi Luli,
      First even though your description is correct, it might be easier for you to think of sshfs mounts as remote-server and local-server instead of server 1 and server 2. So if you are “sharing” data from server 1 = remote-server. And if you want to mount the “share” on server2 = local-server.

      So on your server2 (local-server) you will 1) install sshfs(important) 2)edit the /etc/fstab file directing server1:/path/you/want/to/mount /local/path/on/local/server fuse.sshfs and-then,whatever,syntax,works,here,for,you [tab] 0 [tab] 0

  • tukoz Feb 26, 2016 @ 13:24

    The mount on-demand setup *requires* ROOT ssh access to the server. That should be clearly noted.

  • christopherbalz Dec 25, 2016 @ 14:49

    On Ubuntu 16.04 LTS, I needed to uncomment “allow_other” in `/etc/fuse.conf` and use that option as a `-o` option. Otherwise, I could not access the mounted filesystem as my regular (non-root) user.

  • Nikolay Nikolov Aug 16, 2017 @ 8:00

    You have typo error in :

    Now, edit the /etc/fstab file, enter:

    sudo vi /etc/fstat

  • Sal Aug 17, 2017 @ 2:11

    Would you add example to cover using keys for authentication and mounting for mounting the sshfs?

  • Naura Nov 25, 2017 @ 6:43


    whats the difference between sshfs VS mount?

    i see my coworker doing something like this to mount remote directory to his server

    mount :/path/files/ /home//files

    Even its working, but is it ok?


Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum