How To Mount Remote File Systems using SSHFS on Linux
SSHFS (SSH File System) is a command-line tool that uses SSH connections to establish local access to remote physical or virtual drives, simplifying remote file management.
This article explains how to use SSHFS to mount remote file systems on Linux
Install SSHFS
The command to install SHFS depends on the Linux distribution and the package manager running on the system. Here are the commands for the two most common cases:
- Install SSHFS on Ubuntu/Debian system using apt package manager:
apt install sshfs -y
Install SSHFS on a Centos system using the yum manager:
yum install fuse-sshfs
Mount Remote File System on Linux
The terminal is the simplest way to mount a remote directory in Linux. The steps below provide a detailed explanation of the mounting procedure.
Step 1: Create Mount Point
To create a mount point directory in /mnt, type the command below:
mkdir /mnt/[mount-point-directory]
Replace [mount-point-directory] with a new directory name.
Step 2: Mount Remote File System Using SSHFS
Mount the remote file system to the mount point created in the previous step. Use the following SSHFS syntax:
sshfs -o [options] [remote-user]@[remote-host]:/[path to remote directory] /mnt/[mount-point-directory]/
Then enter the password when requested.
Our example:
sshfs -o allow_other,default_permissions root@IP address:/home/VPS/ /mnt/greentest/
Enter the password when requested.
The above command mounts a remote directory at 64.44.x.x under the name VPS to the /mnt/greentest/ mount point.
The -o
flag introduces the following options:
allow_other
. Allows access to users other than root.default_permissions
. Enables permission checking by the kernel.
For a comprehensive list of available options, enter:
sshfs -h
Step 3: Check Mounted File System
Check if the file system is mapped correctly by navigating to the mount point directory with the cd command:
cd /mnt/[mount-point-directory]
Step 4: Unmount Remote File System on Linux.
To stop using the mount point and interrupt the connection with the remote file system, unmount the remote directory with the umount command:
umount /mnt/[mount-point-directory]
If successful, the command provides no output.
Conclusion
SSHFS provides a secure way to mount a remote directory to a local machine. The connection uses the SSH file transfer protocol for each transferred file, ensuring secure communication between two points. Good luck!