SSHFS (Secure SHell FileSystem) is a network file system based on SSH protocol, which allows users to access and manage remote files locally as they operate local files by mounting the file system of remote servers. It uses the encryption and authentication mechanism provided by SSH to ensure the security of data transmission. It is suitable for scenarios requiring remote file access without additional configuration of a dedicated file sharing protocol. Through a simple mount command (such as ` sshfs user@remote :/ Path/local/mountpoint `), SSHFS can quickly establish a connection without complex settings. It is an efficient, convenient and secure remote file sharing method.
In this article, our records will show you how to install and use the SSHFS client on any Linux distribution, and mount the remote Linux file system or directory on the local Linux machine.
First, install SSHFS on the Linux system
By default, the sshfs package does not exist in all mainstream Linux distributions. You need to enable epel in your Linux system and install SSHFS and its dependencies with the help of the Yum command line.
On the Fedora 22+release:
# yum install sshfs # dnf install sshfs
Debian/Ubuntu based system:
$ sudo apt-get install sshfs
Second, create the SSHFS mount directory
After you install the SSHFS package, you need to create a mount point directory where you will mount your remote file system. For example, we create a mount directory under/mnt/temint.
#Mkdir/mnt/temint [on Fedora 22+release]
$sudo mkdir/mnt/techint [Debian/Ubuntu based system]
Third, use SSHFS to mount remote file systems
After you have created your mount point directory, now use the root user to run the following command line to mount the remote file system in the/mnt/temint directory. Depending on your situation, the mount directory can be any directory.
The following command line will mount a/home/tecmint directory called Remote under the local/mnt/tecmint directory. (Don't forget to replace x.x.x.x with your IP address and mount point).
# sshfs tecmint@x.x.x.x :/ home/tecmint/ /mnt/tecmint
$ sudo sshfs -o allow_other tecmint@x.x.x.x :/ Home/techint//mnt/techint [Debian/Ubuntu based system]
If your Linux server is configured for SSH key based authorization, you will need to use the command line shown below to specify the path of your public key.
# sshfs -o IdentityFile=~/.ssh/id_rsa tecmint@x.x.x.x :/ home/tecmint/ /mnt/tecmint
$ sudo sshfs -o allow_other, IdentityFile=~/.ssh/id_rsa tecmint@x.x.x.x :/ home/tecmint/ /mnt/tecmint
[Debian/Ubuntu based system]
Fourth, verify that the remote file system is mounted successfully
If you have successfully run the above command without any errors, you will see the list of remote files and directories mounted in the/mnt/tecmint directory
# cd /mnt/tecmint
# ls
[root@ tecmint]# ls 12345.jpg ffmpeg-php-0.6.0.tbz2 Linux news-closeup.xsl s3.jpg cmslogs gmd-latest.sql.tar.bz2 Malware newsletter1.html sshdallow epel-release-6-5.noarch.rpm json-1.2.1 movies_list.php pollbeta.sql ffmpeg-php-0.6.0 json-1.2.1.tgz my_next_artical_v2.php pollbeta.tar.bz2
Fifth, use the df - hT command to check the mount point
If you run the df - hT command, you will see the mount point of the remote file system.
# df -hT
Sample output:
Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 730M 0 730M 0% /dev tmpfs tmpfs 150M 4.9M 145M 4% /run /dev/sda1 ext4 31G 5.5G 24G 19% / tmpfs tmpfs 749M 216K 748M 1% /dev/shm tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs tmpfs 749M 0 749M 0% /sys/fs/cgroup tmpfs tmpfs 150M 44K 150M 1% /run/user/1000 tecmint@192.168.0.102 :/ home/tecmint fuse.sshfs 324G 55G 253G 18% /mnt/tecmint
VI. Permanently mount the remote file system
In order to mount the remote file system permanently, you need to modify a file called
/etc/fstab
File. Follow this and open the file using your favorite editor.
# vi /etc/fstab
$sudo vi/etc/fstab [Debian/Ubuntu based system]
Move to the bottom of the file and add the following line, save the file and exit. The following entries indicate that the remote file system is mounted using the default settings.
sshfs# tecmint@x.x.x.x :/ home/tecmint/ /mnt/tecmint fuse.sshfs defaults 0 0
Ensure that SSH login without password is allowed between servers, so that the file system can be automatically mounted after the system is restarted.
If your server is configured for SSH key based authentication, please join the following line:
sshfs# tecmint@x.x.x.x :/ home/tecmint/ /mnt/tecmint fuse.sshfs IdentityFile=~/.ssh/id_rsa defaults 0 0
Next, you need to update the fstab file to make the changes take effect.
# mount -a $sudo mount - a [Debian/Ubuntu based system]
Seventh, unmount the remote file system
To unmount a remote file system, simply issue the following command.
# umount /mnt/tecmint
Article reference: https://linux.cn/article-7855-1.html