Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SSHFS to remotely mount a file system in Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today Xiaobian to share with you how to use SSHFS remote mount file system related knowledge points in Linux, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone's reference, I hope you have something to gain after reading this article, let's learn about it together.

SSHFS is a network file system client that connects to a server via SSH. SSHFS allows you to mount remote file systems using SFTP. Most VPS SSH servers support and enable this SFTP access by default, so SSHFS is very simple to use without any action on the server side.

Step 1: Install SSHFS on Linux

By default, the sshfs package does not exist in all major Linux distributions. You need to enable epel on your Linux system and install SSHFS and its dependencies with the help of the Yum command line.

# yum install sshfs# dnf install sshfs $ sudo apt-get install sshfs Step 2: Create 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 mount directories under/mnt/tecmint.

# mkdir /mnt/tecmint$ sudo mkdir /mnt/tecmint Step 3: Mount the remote file system using SSHFS

When you have created your mount point directory, now run the following command line as root to mount the remote file system in the/mnt/tecmint directory. The mount directory can be any directory depending on your situation.

The following command line will mount a directory called remote called/home/tecmint 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/tecmint/ /mnt/tecmint Debian/Ubuntu based systems

If your Linux server is configured for SSH key-based authorization, you will need to specify the path to your public key using the command line shown below.

# 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 Step 4: Verify that the remote file system is successfully mounted.

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

# cd /mnt/tecmint# ls[root@ tecmint]# ls12345.jpg ffmpeg-php-0.6.0.tbz2 Linux news-closeup.xsl s3.jpgcmslogs gmd-latest.sql.tar.bz2 Malware newsletter1.html sshdallowepel-release-6-5.noarch.rpm json-1.2.1 movies_list.php pollbeta.sqlffmpeg-php-0.6.0 json-1.2.1.tgz my_next_artical_v2.php pollbeta.tar.bz2 Step 5: Check mount points using df -hT

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

# df -hT

Sample output:

Filesystem Type Size Used Avail Use% Mounted onudev devtmpfs 730M 0 730M 0% /devtmpfs tmpfs 150M 4.9M 145M 4% /run/dev/sda1 ext4 31G 5.5G 24G 19% /tmpfs tmpfs 749M 216K 748M 1% /dev/shmtmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/locktmpfs tmpfs 749M 0 749M 0% /sys/fs/cgrouptmpfs tmpfs 150M 44K 150M 1% /run/user/1000tecmint@192.168.0.102:/home/tecmint fuse.sshfs 324G 55G 253G 18% /mnt/tecmint Step 6: Mount the remote file system permanently

In order to permanently mount remote file systems, you need to modify a file called/etc/fstab. Do this and open the file using your favorite editor.

# vi /etc/fstab$ sudo vi /etc/fstab Debian/Ubuntu based systems

Move to the bottom of the file and add the following line, save the file and exit. The following entry indicates that a remote file system is mounted using default settings.

sshfs#tecmint@x.x.x.x:/home/tecmint/ /mnt/tecmint fuse.sshfs defaults 0 0

Make sure SSH password-less logins are allowed between servers so that file systems can be mounted automatically after a system reboot.

If your server is configured for SSH key-based authentication, add 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 for the changes to take effect.

# mount -a$ sudo mount -a Step 7: Uninstall the remote file system

To unmount a remote file system, simply issue the following command.

#mount/mnt/tecmint The above is "How to use SSHFS to remotely mount file systems in Linux" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 258

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report