Mount a Remote Filesystem over SSH with SSHFS

Mount SSH with SSHFS Whizoweb

SSH (Secure Shell) is a protocol for secure network communication and remote access to networked computers. It provides secure encrypted communications between two untrusted hosts over an insecure network. SSH is often used for remote login and remote file transfer, and is a secure alternative to Telnet and FTP.

With the help of SSHFS, you can easily use your existing SSH connection to mount a remote directory in a secure way, without using additional services like NFS or Samba.

SSHFS (Secure Shell File System) is a file system client based on the SSH protocol that allows users to mount a remote file system over a secure SSH connection. It allows users to access files on a remote server as if they were on the local file system, while providing encrypted data transfer and authentication. SSHFS is often used for remote file access, backup and remote development work.

To install sshfs, type the following command in your terminal:

Command: apt install sshfs

sshfs Techhyme

Suppose you have a running SSH server with IP 10.228.0.82, and we want to mount the remote /etc/logstash/conf.d directory locally on ~/root/techhyme.

Let’s create a directory named as “techhyme” under /root.

sshfs Techhyme

Now to mount the remote directory we invoke sshfs in the following way:

Command: sshfs root@10.228.0.82:/etc/logstash/conf.d/ /root/techhyme

sshfs Techhyme

If the command is executed without errors, the content of the remote /root/techhyme directory becomes accessible under the local directory:

sshfs Techhyme

Furthermore, the privileges we have on the remote directory are the privileges the remote user has: by default local permissions are ignored by sshfs.

Once the remote directory is mounted, you are able to access its content without problems. If you try to access it as another user, even as root, however, you will fail to mount or list:

This error is due to the fact that, by default, only the user which performs the mount is allowed to access the mounted filesystem.

In order to change this behavior, and allow any user to access the mount point, you must pass the user_allow_other option when using sshfs.

Edit the /etc/fuse.conf file, and remove the comment from the user_allow_other line as shown below:

sshfs Techhyme

You should now be able to access the remote directory as any local user (which is allowed to reach the mount point locally, of course). With this setup, any local user will able to perform every action the remote user is entitled to perform on the remote directory.

You may also like:

Related Posts

Leave a Reply