How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH

[‘

n

The main purpose of writing this article is to provide a step-by-step guide on how to mount remote Linux file system using SSHFS client over SSH.

n

This article is useful for those users and system administrators who want to mount remote file system on their local systems for whatever purposes. We have practically tested by installing SSHFS client on one of our Linux system and successfully mounted remote file systems.

n

Before we go further installation let’s understand about SSHFS and how it works.

n

Sshfs Mount Remote Linux Filesystem or Directory
Sshfs Mount Remote Linux Filesystem or Directory

n

What Is SSHFS?

n

SSHFS stands for (Secure SHell FileSystem) client that enable us to mount remote filesystem and interact with remote directories and files on a local machine using SSH File Transfer Protocol (SFTP).

n

Suggested Read: 10 sFTP Command Examples to Transfer Files on Remote Servers in Linux

n

SFTP is a secure file transfer protocol that provides file access, file transfer and file management features over Secure Shell protocol. Because SSH uses encryption while transferring files over the network from one computer to another computer and SSHFS comes with built-in FUSE (Filesystem in Userspace) kernel module that allows any non-privileged users to create their file system without modifying kernel code.

n

In this article, we will show you how to install and use SSHFS client on any Linux distribution to mount remote Linux filesystem or directory on a local Linux machine.

n

Step 1: Install SSHFS Client in Linux Systems

n

By default sshfs packages does not exists on all major Linux distributions, you need to enable epel repository under your Linux systems to install sshfs with the help of Yum command with their dependencies.

n

# yum install sshfsrn# dnf install sshfs              [On Fedora 22+ releases]rn$ sudo apt-get install sshfs     [On Debian/Ubuntu based systems]rn

n

Step 2: Creating SSHFS Mount Directory

n

Once the sshfs package installed, you need to create a mount point directory where you will mount your remote file system. For example, we have created mount directory under /mnt/tecmint.

n

# mkdir /mnt/tecmintrn$ sudo mkdir /mnt/tecmint     [On Debian/Ubuntu based systems]rn

n

Step 3: Mounting Remote Filesystem with SSHFS

n

Once you have created your mount point directory, now run the following command as a root user to mount remote file system under /mnt/tecmint. In your case the mount directory would be anything.

n

The following command will mount remote directory called /home/tecmint under /mnt/tecmint in local system. (Don’t forget replace x.x.x.x with your IP Address and mount point).

n

# sshfs [emailxa0protected]:/home/tecmint/ /mnt/tecmintrn$ sudo sshfs -o allow_other [emailxa0protected]:/home/tecmint/ /mnt/tecmint     [On Debian/Ubuntu based systems]rn

n

If your Linux server is configured with SSH key based authorization, then you will need to specify the path to your public keys as shown in the following command.

n

# sshfs -o IdentityFile=~/.ssh/id_rsa [emailxa0protected]:/home/tecmint/ /mnt/tecmintrn$ sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_rsa [emailxa0protected]:/home/tecmint/ /mnt/tecmint     [On Debian/Ubuntu based systems]rn

n

Step 4: Verifying Remote Filesystem is Mounted

n

If you have run the above command successfully without any errors, you will see the list of remote files and directories mounted under /mnt/tecmint.

n

# cd /mnt/tecmintrn# ls

n

[[emailxa0protected] tecmint]# lsrn12345.jpg                       ffmpeg-php-0.6.0.tbz2                Linux                                           news-closeup.xsl     s3.jpgrncmslogs                         gmd-latest.sql.tar.bz2               Malware                                         newsletter1.html     sshdallowrnepel-release-6-5.noarch.rpm     json-1.2.1                           movies_list.php                                 pollbeta.sqlrnffmpeg-php-0.6.0                json-1.2.1.tgz                       my_next_artical_v2.php                          pollbeta.tar.bz2

n

Step 5: Checking Mount Point with df -hT Command

n

If you run df -hT command you will see the remote file system mount point.

n

# df -hT

n

Sample Output

n

Filesystem                          Type        Size  Used Avail Use% Mounted onrnudev                                devtmpfs    730M     0  730M   0% /devrntmpfs                               tmpfs       150M  4.9M  145M   4% /runrn/dev/sda1                           ext4         31G  5.5G   24G  19% /rntmpfs                               tmpfs       749M  216K  748M   1% /dev/shmrntmpfs                               tmpfs       5.0M  4.0K  5.0M   1% /run/lockrntmpfs                               tmpfs       749M     0  749M   0% /sys/fs/cgrouprntmpfs                               tmpfs       150M   44K  150M   1% /run/user/1000rn[emailxa0protected]:/home/tecmint fuse.sshfs  324G   55G  253G  18% /mnt/tecmintrn

n

Suggested Read: 12 Useful “df” Commands to Check Disk Space in Linux

n

Step 6: Mounting Remote Filesystem Permanently

n

To mount remote filesystem permanently, you need to edit the file called /etc/fstab. To do, open the file with your favorite editor.

n

# vi /etc/fstabrn$ sudo vi /etc/fstab     [On Debian/Ubuntu based systems]         rn

n

Go to the bottom of the file and add the following line to it and save the file and exit. The below entry mount remote server file system with default settings.

n

sshfs#[emailxa0protected]:/home/tecmint/ /mnt/tecmint fuse.sshfs defaults 0 0rn

n

Make sure you’ve SSH Passwordless Login in place between servers to auto mount filesystem during system reboots..

n

If your server is configured with SSH key based authorization, then add this line:

n

sshfs#[emailxa0protected]:/home/tecmint/ /mnt/tecmint fuse.sshfs IdentityFile=~/.ssh/id_rsa defaults 0 0rn

n

Next, you need to update the fstab file to reflect the changes.

n

# mount -arn$ sudo mount -a   [On Debian/Ubuntu based systems]rn

n

Step 7: Unmounting Remote Filesystem

n

To unmount remote filesystem, jun issue the following command it will unmount the remote file system.

n

# umount /mnt/tecmint

n

That’s all for now, if you’re facing any difficulties or need any help in mounting remote file system, please contact us via comments and if you feel this article is much useful then share it with your friends.

n

‘]