How to mount a remote directory in Linux using sshfs

Step1: Installing Package

On Ubuntu/Debain

apt-get install build-essential libcurl4-openssl-dev libxml2-dev libfuse-dev comerr-dev libfuse2 libidn11-dev libkadm55 libkrb5-dev libldap2-dev libselinux1-dev libsepol1-dev pkg-config fuse-utils sshfs

If you get any errors just remove the package that gave the error. In my case I had to remove  libkadm55.

Step2: Once the packages are installed we have to create a mount point and mount our  server data using sshfs command, for which we require  username/password. Here are my details for this task.

My Username: root
My password: password!
My Server:
My mount point: /mnt/extsystem

Now create the mount point and mount SSH account data.

#mkdir /mnt/extsystem
#sshfs root@ /mnt/extsystem/
root@'s password:

Step3: The above command will mount the ‘mountdir’ directory in server. To specift the port exchage the second command with

#sshfs -p 3244 root@ /mnt/extsystem/

To test out your setup, check if you are able to see data

#cd /mnt/extsystem

You can type ‘mount’ to see if it mounted properly

Step4: So what about mounting it permanently?. We can do it by editing our fstab

#vim /etc/fstab  
#nano /etc/fstab

go to last line and type below line

sshfs#root@ /mnt/extsystem fuse defaults,port=3244 0 0

Save the file and exit. Now run mount -a to update the fstab file state to kernel.

Note: Its not advisable to write passwords in human readable files like /etc/fstab.

#mount -a

Let me explain what entry in fstab indicates. We are mentioning mount user root data which is located on server on to /mnt/ssh using fuse file system with default settings.

Step5: What about unmounting this drive?

#umount /mnt/ssh
fusermount -u /mnt/extsystem (recommended)

Notes: typing ‘fusermount -u [TAB] ‘ can help you quickly find mounts

Your ssh session will automatically log out if it is idle. To keep the connection active (alive) add this to ~/.ssh/config or to/etc/ssh/ssh_config on the client.

ServerAliveInterval 5

This will send a “keep alive” signal to the server every 5 seconds. You can usually increase this interval, and I use 120.

Enjoy your multiple mounts! 


How to mount a remote directory in Linux using sshfs.
Ubuntu Documentation

You may also like...

Leave a Reply