Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Mount a Remote Directory With SSHFS

Rumi, March 2, 2017March 7, 2017

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:

Installing SSHFS on a Ubuntu/Debian/Mint Linux

Type the following apt-get command:

sudo apt-get install sshfs

Sample outputs:

[sudo] password for tweenpath: 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following NEW packages will be installed:
 sshfs
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 http://mirror.ox.ac.uk/sites/archive.ubuntu.com/ubuntu/ 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 (2.6.7.1-1ubuntu1) ...
Setting up sshfs (2.5-1ubuntu1) ...

Installing SSHFS on an Arch Linux

Type the following command:

sudo pacman -S sshfs fuse

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 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
=======================================================================================================================
Installing:
 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  

Installed:
 fuse-sshfs.x86_64 0:2.4-1.el6  

Dependency Installed:
 fuse.x86_64 0:2.8.3-4.el6  

Complete!

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@192.168.1.142:/ /mnt/server1/

## OR use ssh key based login ##

sudo sshfs -o IdentityFile=~/.ssh/keyfile /mnt/server1/

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@192.168.1.142:/ 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

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 tweenpath 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 tweenpath tweenpath 4096 Mar 8 04:34 /home/tweenpath/server1

To mount the remote file system, enter:

sshfs -o idmap=user root@192.168.1.142:/ $HOME/server1
df 
ls -l $HOME/server1

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?

Edit the /etc/fstab file, enter:

sudo vi /etc/fstat

The syntax is:

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

Examples
Add the following entry at the bottom of the file:

sshfs#root@192.168.1.142:/ /mnt/server1

Another example with additional options:

sshfs#$root@192.168.1.142:/ /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:

tweenpath@tweenpath.net/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

Save and close the file. Where,

  1. root@192.168.1.142 : 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.

P.S: If you are troubled with file permissions- try this instead-

sshfs -o allow_other user@myserver:/home/user/myprojects ~/mount/myprojects

 

 

Administrations SSHFS

Post navigation

Previous post
Next post

Comments (2)

  1. warren says:
    May 13, 2020 at 9:17 am

    your SSL cert is expired

    Reply
    1. Rumi says:
      May 24, 2020 at 4:50 pm

      Thanks! Renewed!!!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes