Typically, we mount local filesystem or directory in our Linux system. But sometimes you may need to mount remote filesystem or directory in Linux. In this article, we will learn how to mount remote filesystem or directory in Linux. This is useful for system administrators who need to work with remote systems. We will be using SSHFS (Secure Shell File system) for this purpose. It allows you to access & transfer files & directories over SSH. It also allows you to create a remote filesystem, without affecting kernel code.
Here are the steps to mount remote filesystem or directory in Linux.
First of all, open terminal and run the following command to install SSHFS on your local client system.
# yum install sshfs # dnf install sshfs [On Fedora 22+ releases] $ sudo apt-get install sshfs [On Debian/Ubuntu based systems]
Once SSHFS is installed, create a mount directory with the following command.
# mkdir /mnt/test [RHEL/CentOS/Fedora] $ sudo mkdir /mnt/test [On Debian/Ubuntu based systems]
Once you have created the mount point, run the following command as root to mount your remote file system at /mnt/test. Replace user_name as remote SSH username, and x.x.x.x with the remote SSH IP address. The following command will mount the remote directory /home/test at local mount point /mnt/test.
# sshfs user_name@x.x.x.x:/home/test/ /mnt/test [RHEL/CentOS/Fedora] $ sudo sshfs -o allow_other user_name@x.x.x.x:/home/test/ /mnt/test [Ubuntu/Debian]
You will be asked for SSH password which you need to enter. If your remote SSH user is configured to use key-based authentication then you need to use the following command instead.
# sshfs -o IdentityFile=~/.ssh/id_rsa test@x.x.x.x:/home/test/ /mnt/test [RHEL/CentOS/Fedora] $ sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_rsa tecmint@x.x.x.x:/home/test/ /mnt/test [Ubuntu/Debian]
Once the remote filesystem is mounted you can access its contents as if it were a local folder /mnt/test.
# cd /mnt/tecmint # ls
You will also be able to see the remote filesystem using the following command.
# df -hT
The above steps will mount the remote filesystem only until the next reboot. Once you reboot your local system, the above mounting will be lost. If you want to permanently mount a remote filesystem, you need to make the following changes to /etc/fstab file.
Open it in a text editor with the following command.
# vi /etc/fstab [RHEL/CentOS/Fedora] $ sudo vi /etc/fstab [On Debian/Ubuntu based systems]
Add the following line to the bottom of the file. This command will be auto executed every time your system boots. Replace user_name with your SSH username and x.x.x.x with the remote IP address.
sshfs#user_name@x.x.x.x:/home/test/ /mnt/test fuse.sshfs defaults 0 0
Make sure you have enabled passwordless SSH login in your remote server. Otherwise, the mounting will fail, since it did not receive a password.
In case your remote server accepts key-based authentication, add the following command instead.
sshfs#user_name@x.x.x.x:/home/test/ /mnt/test fuse.sshfs IdentityFile=~/.ssh/id_rsa defaults 0 0
After you add the above line, add the following command.
# mount -a [RHEL/CentOS/Fedora] $ sudo mount -a [On Debian/Ubuntu based systems]
Save and close the file.
If you want to unmount the remote filesystem, run the following command.
# umount /mnt/test
In this article, we have learnt how to mount remote file system in Linux. It is a great way to easily access remote files from your local system.
Also read:
How to Copy Files from Linux to Windows
How to Set Process Priority in Linux
How to Change Default MySQL Data Directory
How to Fix firewall-cmd Command Not Found
How to Protect Hard & Soft Links in Linux
The post How to Mount Remote Filesystem or Directory in Linux appeared first on Fedingo.
One of the most critical gaps in traditional Large Language Models (LLMs) is that they…
Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…
What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…
Wouldn’t it be wonderful to wake up one day with a desire to explore AI…
Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…
Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…