Detailed explanation of how to mount remote file systems via SSH on Linux

Detailed explanation of how to mount remote file systems via SSH on Linux

Features of SSHFS:

Based on FUSE (the best userspace file system framework for Linux)

Multithreading: There can be multiple requests on the server

Allow large reads (up to 64k)

Cache directory contents

Step 1: Install fuse-sshfs

For CentOS/RHEL users, fuse-sshfs is available under epel repository, so make sure you have epel repository installed in your system. Now execute the following command to install it

On CentOS/RHELL:

#yum install fuse-sshfs

On Ubuntu and Dabian:

$ sudo apt-get update

$ sudo apt-get install sshfs

Step 2: Mount the remote directory

Let’s mount the remote server directory using sshfs and make sure the remote system is running an ssh server and the ssh connection with the system is working properly.

First create the mount point

# mkdir /mntssh

Let's mount the remote directory. For this example, we will mount the /home/remoteuser directory from the 192.168.1.12 (remote.example.com) system to the local system.

# sshfs [email protected]:/home/remoteuser /opt/mntssh

Sample Output

The authenticity of host 'remote.example.com (192.168.1.12)' can't be established.

RSA key fingerprint is 77:85:9e:ff:de:2a:ef:49:68:09:9b:dc:f0:f3:09:07.

Are you sure you want to continue connecting (yes/no)? yes

[email protected]'s password:

Step 3: Verify Installation

After mounting the remote file system on the local mount point, verify it by running the mount command.

# mount

 

/dev/mapper/vg_svr1-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)[email protected]:/home/remoteuser on /mntssh type fuse.sshfs (rw,nosuid,nodev)

Also navigate to your mount point and you will see the files from the remote system

# cd /mntssh

# ls

Step 4: Mount the directory at system boot

If you want to automatically mount the remote file system on every system reboot, add the following entry in /etc/fstab file. Make sure you have key-based ssh installed between the remote and local systems.

[email protected]:/home/remoteuser /mntssh fuse.sshfs defaults 0 0

Step 5: Unmount the directory

If your work ends and you no longer need the mounted directory, then simply uninstall using the following command.

#umount /mntssh

You may also be interested in:
  • Detailed explanation of how to pass password to ssh/scp command in bash script
  • CentOS method to modify the default ssh port number example
  • Detailed installation and use of SSH in Ubuntu environment
  • Instructions for deploying projects to remote machines using the Publish Over SSH plugin in Jenkins
  • CentOS 6.5 configuration ssh key-free login to execute pssh command explanation
  • Ubuntu basic settings: installation and use of openssh-server
  • How to install MySQL via SSH on a CentOS VPS
  • How to configure ssh/sftp and set permissions under Linux operating system
  • Implementation of ssh non-secret communication in linux
  • Explanation of Mac connecting to remote servers through SSH in different terminals

<<:  Understanding and using React useEffect

>>:  js drag and drop table to realize content calculation

Recommend

Share the problem of Ubuntu 19 not being able to install docker source

According to major websites and personal habits, ...

Nginx+FastDFS to build an image server

Installation Environment Centos Environment Depen...

CSS implements the web component function of sliding the message panel

Hello everyone, I wonder if you have the same con...

Use and understanding of MySQL triggers

Table of contents 1. What is a trigger? 2. Create...

Pure CSS to achieve the water drop animation button in Material Design

Preface You should often see this kind of special...

js realizes a gradually increasing digital animation

Table of contents background Achieve a similar ef...

Simple operation of installing vi command in docker container

When using a docker container, sometimes vim is n...

Install tomcat and deploy the website under Linux (recommended)

Install jdk: Oracle official download https://www...

JS implements random roll call system

Use JS to implement a random roll call system for...

Share MySql8.0.19 installation pit record

The previous article introduced the installation ...

WeChat applet realizes chat room function

This article shares the specific code of WeChat a...

Detailed explanation of MySQL execution plan

The EXPLAIN statement provides information about ...