Regardless of being a Linux user or administrator, you will need to mount remote file system on your local system to meet your considered purposes. Secure SHell FileSystem (SSHF) is the client that enables you to mount remote filesystems and interact with remote directories and files. In this article, you will learn How to Mount Remote File Systems over SSH. Using SFTP or SCP, you can transfer files over an SSH connection.
As an alternative, SSHFS can be installed and used to mount remote directories. This has the important benefit of inheriting permissions from the SSH user on the remote system and requiring no additional settings. When you need to interactively read from a big collection of files on a per-file basis, SSHFS is especially helpful.
Prerequisites to Mount Remote File Systems over SSH
To let this tutorial work correctly, consider the below requirements and continue.
- A remote folder or file system to mount for transferring files.
- Two Linux servers which are configured to allow SSH access between them.
- Access to the command line with administrator privileges.
- The username and host address of the remote server.
Tutorial Mount Remote File Systems Using SSHFS
SSHFS is a command-line tool for securely mounting a server-based remote folder on a local computer. The client extends the SSH file transfer protocol which makes it easier to safely mount a remote file system locally as a disk image. SSHFS enables file access, transfer, and manipulation just like when using a local drive. When transferring a lot of content to and from a distant machine, this method is useful.
Configuring an SMB or NFS allows you to share entire directories or entire filesystems between two remote systems. However, you might face security concerns or other overhead after providing additional dependencies.
Stay with us to review the required steps of mounting remote file system over SSH using SSHFS.
Step 1. Install SSHFS
Most machines do not by default have SSHFS available. Depending on the machine’s operating system, different packages are available. According to your running distribution, find the related command and run it.
Use the command below to install SSHFS on your Ubuntu/Debian system.
sudo apt install sshfs
sudo yum install fuse-sshfs
Download the latest stable version of the FUSE and SSHFS packages in order to install SSHFS on MacOS. Run the SSHFS (pkg file) after the FUSE installer (dmg file).
To use SSHFS on Windows, download and install the latest stable version of WinFS and the newest stable version of SSHFS-Win that is compatible with your system.
Step 2. Mount a Remote File System
Let’s continue to Mount Remote File Systems over SSH. With SSHFS, mounting and unmounting a remote file system is a simple procedure. In a Linux environment, you must first create an empty directory to mount the remote disk in. You can build subdirectories within the
/mnt directory, which is present in most Linux setups, for this use.
First, in the
/mnt folder, create a mount point directory where the remote file system will be mounted:
sudo mkdir /mnt/<folder name>
SSHFS tool, mount a remote directory.
sudo sshfs [-o <options>] <remote user>@<remote host>:/<path to remote directory> /mnt/<folder name>/
Also, you can use the command below to view a comprehensive list of available options.
To check if files in the mounted directory match the contents of the remote directory, use the following command to list them.
ls /mnt/ <folder name>
You can umount this mount if you no longer need it by running:
sudo umount /mnt/ <folder name>
Step 3. Mount the Remote File System Permanently
To Mount Remote File Systems over SSH, complete the required steps by following the third one. To configure a permanent mount using SSHFS, you must add a configuration entry to a file named
/etc/fstab firstly which handles Linux filesystem mounts at startup.
/etc/fstabin your favorite editor. Here we use
sudo nano /etc/fstab
Add an entry like this to the file’s end:
… opera@your_other_server:~/ /mnt/droplet fuse.sshfs noauto,x-systemd.automount,_netdev,reconnect,identityfile=/home/opera/.ssh/id_rsa,allow_other,default_permissions 0 0
Save the file, then exit. Press Ctrl+X, then Y when asked, and then ENTER if you’re using
nano. If the mount is automatically recreated, you can confirm that the
/etc/fstab setup is working by rebooting your local computer, for instance by using the
sudo reboot now command.
How to Mount a Remote File System on Windows
After buying a Remote Windows Server, you might need to mount file systems. There are three methods to mount a remote file system on Windows:
- Windows Explorer
- SSHFS-Win Manager
Let’s learn the way you can use these three methods to Mount Remote File Systems on your Windows system. Mounting a Remote File System on Windows via Windows Explorer is the most common way. Here, we discuss it. Follow the below path:
Using Windows Explorer to Mount a Remote File System on Windows
1. Open the file explorer. from the menu on the left pane, right-click This PC and select the option Map Network Drive.
2. To select the letter of the drive to which you prefer to map the remote file, run the command below:
\\sshfs[.option]\<remote user>@<remote host>[!port][\path]
This way, mounting the remote file system will be done by SSHFS. To map the remote file system, click Finish. An attempt to establish a connection results in a dialog box appearing. Windows Explorer launches and displays the external file system when a connection is made successfully.
3. To check Mounted File System, find the new mounted file system visible from This PC in Windows Explorer under Network locations.
4. Right-click the mounted device and choose Disconnect to unmount the drive.
You’re all set. Let’s review how the second method works.
Using CMD to Mount a Remote File System on Windows
The second method is a simple and quick way. Follow the steps below to use it.
1. To mount the remote file system. Run the following command first:
net use <drive letter>: \\sshfs[.option]\<remote user>@<remote host>[!port][\path]
2. Run the command below to view the currently mounted disks and devices through SSHFS.
It will display the local mount point name and the remote connection point.
3. Also, using CMD enables you to unmount a remote file system on Windows. Use the command below to remove the mapped device from your Windows system.
net use <drive letter>: /delete
Using SSHFS-Win Manager to Mount a Remote File System on Windows
The SSHFS-Win Manager provides a practical and simple-to-use GUI for establishing and managing connections to remote servers. Here are the required steps to use this method to mount a remote file system on Windows.
1. Run the SSHFS-win manager after searching it in the start menu. A GUI interface opens for managing device connections.
2. To add a new connection, click the Add Connection button on the right menu.
Once the menu is popped out, fill out provided fields and select the options for your situation. When finished, click Save after completing the fields. The primary menu displays the recently established server connection.
3. To view the contents, click the socket icon next to your connection name to establish a connection. The socket icon changes to a green connected socket, and a folder icon appears if all is done correctly. Just click the folder icon to view the contents of the remote file system.
4. Again, you can unmount a remote file system on Windows while using SSHFS win-Manager method. To do this, , click the socket icon in the SSHFS Win-Manager menu. You can delete the information whenever you do not need the connection by clicking on the Delete mode button.
what is the difference between permanent and temporary SSHFS mount?
Permanent SSHFS mounts aren't always well-liked. Because of how SSH connections and SSHFS work, they are typically more appropriate for short-term, one-time fixes.
How to mount a remote directory without requiring sudo permissions?
Create a user group called
fuse on your local system, by using
sudo groupadd fuse, and then adding your local user to that group, by using
sudo usermod -a -G fuse username .
In this article, you learned How to Mount Remote File Systems over SSH [using SSHFS]. If you follow the above steps properly then you can smoothly install without any errors. A remote folder can be mounted securely on a local machine using SSHFS. Each file that is exchanged across the connection is done so using the secure SSH file transfer protocol, which guarantees two-way communication. Keep in mind to avoid exposing more of the remote filesystem over SSH than you intend.
If you encounter any problems, please do not hesitate to contact us. Our technical support team will try their best to solve your problems.