How to mount a remote directory in Linux using sshfs
Step1: Installing Package
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: 192.168.1.22
My mount point: /mnt/extsystem
Now create the mount point and mount SSH account data.
#mkdir /mnt/extsystem #sshfs firstname.lastname@example.org:/home/user/mountdir /mnt/extsystem/ email@example.com's password:
Step3: The above command will mount the ‘mountdir’ directory in 192.168.1.22 server. To specift the port exchage the second command with
#sshfs -p 3244 firstname.lastname@example.org:/home/user/mountdir /mnt/extsystem/
To test out your setup, check if you are able to see data
#cd /mnt/extsystem #ls
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 or #nano /etc/fstab
go to last line and type below line
email@example.com:/home/user/mountdir /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.
Let me explain what entry in fstab indicates. We are mentioning mount user root data which is located on 10.233.10.212 server on to /mnt/ssh using fuse file system with default settings.
Step5: What about unmounting this drive?
#umount /mnt/ssh OR 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.
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!