Working with remote servers is a common practice in the world of Linux. To manage files and directories on remote systems, you often need to access their file systems. One secure and efficient method for accomplishing this is by mounting the remote file system over SSH (Secure Shell). This guide will walk you through the process of mounting a remote file system over SSH in Linux, enabling you to access and manipulate remote files as if they were on your local machine.
Prerequisites
Before we begin, you will need the following:
- A Linux-based operating system installed on your local machine.
- A remote server running Linux with SSH access.
- SSH keys or a password for authentication.
- SSHFS (SSH File System) package installed on your local machine.
Step 1: Installing SSHFS
SSHFS is a user-space file system client that allows you to mount remote directories over an SSH connection. To install SSHFS, use the package manager for your distribution:
- For Debian-based distributions (e.g., Ubuntu), use the following command:
sudo apt-get install sshfs
- For RHEL-based distributions (e.g., CentOS), use the following command:
sudo yum install sshfs
- For Arch-based distributions, use the following command:
sudo pacman -S sshfs
Step 2: Creating a Mount Point
Before mounting the remote file system, you need to create a mount point on your local machine. This is the directory where the remote file system will be mounted. To create a mount point, use the “mkdir” command:
1 | mkdir /path/to/mount/point |
For example:
mkdir ~/remote-files
Step 3: Mounting the Remote File System
To mount the remote file system, use the “sshfs” command, followed by the remote user, the remote server’s IP address or hostname, the remote directory, and the local mount point:
1 | sshfs [user]@[remote-server]:[remote-directory] [local-mount-point] |
For example:
sshfs [email protected]:/home/john/files ~/remote-files
If you are prompted for a password, enter the remote user’s password. If you have set up SSH keys for authentication, the process will use them automatically.
Step 4: Navigating the Mounted File System
Once the remote file system is mounted, you can access it like any other directory on your local machine. To navigate the remote file system, use standard Linux commands such as “cd”, “ls”, “cp”, “mv”, and “rm”.
For example:
cd ~/remote-files
ls -l
Step 5: Unmounting the Remote File System
To unmount the remote file system, use the “fusermount” command with the “-u” option, followed by the local mount point:
1 | fusermount -u [local-mount-point] |
For example:
fusermount -u ~/remote-files
Conclusion
By mounting a remote file system over SSH in Linux, you can seamlessly access and manage files on remote servers as if they were on your local machine. This secure and efficient method simplifies remote file management and streamlines your workflow. With the help of this guide, you can now effortlessly mount remote file systems and take full advantage of the power and flexibility that Linux offers.
4 Comments
This did not work on RHEL 8.
sudo yum install fuse-sshfs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Red Hat Enterprise Linux 8 for x86_64 – AppStre 41 MB/s | 26 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 – BaseOS 44 MB/s | 28 MB 00:00
No match for argument: fuse-sshfs
Error: Unable to find a match: fuse-sshfs
We want to monitor SSHFS mount point with SNMP in Ubuntu but it doesn’t show any SSHFS mount point. Maybe because it is encrypted. How we can solve this?
Note: we don’t have problem with NFS.
snmpwalk -v 2c -c public localhost UCD-SNMP-MIB::dskTable
or
snmpwalk -v 2c -c public localhost HOST-RESOURCES-MIB::hrFSRemoteMountPoint
When we request with above commands there is no mountpoint in result but we have MountPoint when we do df.
df
HI i did all of the things and it has an error ” connection peer rest”
what should I do ?
Nice article… Something new for me…