How to mount remote directories with SSHFS

sshfs

SSH (Secure Shell) is a protocol that allows us securely access remote computers and its possibilities are enormous since basically what we will be doing when using it is to have a server as if we were sitting in front of its screen and keyboard. Today it is available on * nix through OpenSSH, the open implementation that arrived back in 1999, and we are going to show a very interesting possibility for system administrators such as mount remote directories on a local machine using SSHFS.

Thanks to this we can use a directory on a remote computer as part of the directory structure of our local computer, with the consequent advantages such as being able to use scripts and others in a simpler way. And of course, we can also use a file explorer and thanks to it copy or move files and folders by dragging and dropping, so let's see how to get started.

Logically, the first thing we are going to need is to have an OpenSSH installation already running on the server we are going to access and also on the client. Then it is time to install sshfs, something very simple thanks to the fact that this tool already It is available in the official Ubuntu repository (and also at its reduced size of less than 50 Kb, so it installs in a few seconds):

# apt-get install shfs

Now that we have installed sshfs we have to use it according to its use, similar to ssh in the fact that we will have to authenticate us by username and password, which is why it goes without saying that said user must be a valid account on the remote computer (in our example it will be the computer with IP 192.168.1.100).

sshfs user @ remotecomputer: / path / to / directory

So what we need is to create the local directory that will point to the remote directory (which in our example can be / home / programs), which we do as follows:

#mkdir / mnt / server

Then we mount the remote directory in this directory, doing:

#sshfs root@192.168.1.100: / home / programs / / mnt / server

We will be asked for the root password on the remote computer, which we must know so we enter it and after this we will have mounted the remote server on our local computer. Something that we can easily check if we run:

$ df -h

O:

ls -l / mnt / server

Once we start using this we will surely appreciate the great comfort it offers us, and if that is the case we may want this process to be carried out automatically when we start our equipment. And we can get it, for which we have to edit the file / etc / fstab:

#vi / etc / fstab

We add the following entry:

sshfs#$root@192.168.1.100: / / mnt / server fuse defaults, idmap = user, allow_other, reconnect, _netdev, users 0 0

With this we will have what we want, but we can go further and if our team has the controversial systemd as a starting system we can use the assembly 'on demand', that is, it will be done automatically when we need it (for example, when we try to access the local directory that is linked to the remote directory).

user @ remotecomputer: / home / programs / / mnt / server fuse.sshfs noauto, x-systemd.automount, _netdev, users, idmap = user, allow_other, reconnect 0 0


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.