TranslateProject/sources/tech/20151027 How to Use SSHfs to Mount a Remote Filesystem on Linux.md
2015-10-27 14:27:28 +08:00

4.2 KiB
Raw Blame History

How to Use SSHfs to Mount a Remote Filesystem on Linux

Have you ever wanted to mount remote file systems locally over secure shell? If so, SSHfs may be just what youre looking for. It makes use of SSH and Fuse to allow you to mount remote computers (or servers) locally.

Note: this article assumes that you understand how SSH works and that it is already set up on your system.

Preparation

Before SSHfs can be mounted, things must be set up installing SSHfs, as well as installing the fuse package to your system. Youll also need to create a group for fuse, add your user to said group and create the folder where the remote file system will reside.

To install the packages on your Ubuntu Linux installation, just enter this command into a terminal window:

sudo apt-get install sshfs fuse

sshfs-install-fuse-ubuntu

If youre not using Ubuntu, just search for the package names in your distributions package manager. It would be best to just search for terms relating to fuse or SSHfs, since the package could be named slightly different depending on what youre running.

After installing the packages to your system, its time to create the fuse group. When you install fuse, a group should be created on your system. If this isnt the case, enter this command into a terminal window to create it on your Linux installation:

sudo groupadd fuse

After the group has been added, add your user to it.

sudo gpasswd -a "$USER" fuse

sshfs-add-user-to-fuse-group

Dont worry about $USER in the command above. The shell will replace it with your own username automatically. Now that the group stuff is taken care of, its time to create the folder where the the remote files will mount to.

mkdir ~/remote_folder

With the local folder created on your computer, your remote file system is now set up to be mounted over SSHfs.

Mounting the remote file system

To mount your remote file system to your machine, youll need to enter a lengthy command into your terminal window.

sshfs -o idmap=user username@ip.address:/remote/file/system/ ~/remote

sshfs-mount-file-system-to-local-folder

Note: It is also possible to mount your SSHfs file system with an SSH keyfile. Just replace the sshfs -o idmap=user part of the command above with sshfs -o IdentityFile=~/.ssh/keyfile, and youll be good to go.

When this command has been entered, youll be prompted to enter the remote users password. If the login is successful, your remote file system will be mounted in the ~/remote_folder directory that was created earlier.

sshfs-mount-file-system-to-local-folder-2

Done with your remote file system and want to un-mount it? Its easy? Just enter this command into the terminal:

sudo umount ~/remote_folder

This simple command will disconnect your remote connection as well as empty out your remote folder.

Conclusion

There are many tools for accessing remote files to mount locally on Linux. With that being said, few, if any, take advantage of the powerful feature-set that SSH has. I hope that with the help of this tutorial, you, too, will learn just how powerful of a tool SSHfs can be.

What are your thoughts on SSHfs? Let us know in the comment section below!


via: https://www.maketecheasier.com/sshfs-mount-remote-filesystem-linux/

作者:Derrik Diener 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出