Using SSHFS to Mount Remote Directories
Updated , by Linode
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
SSHFS (Secure Shell FileSystem), is a tool that allows users to securely access remote filesystems over the SSH protocol. This guide will get you started with SSHFS on your Linode. SSHFS can eliminate the need to use FTP/SFTP to transfer files to and from a remote server.
Before You Begin
This guide will assume you have two systems set up:
A remote system running Ubuntu 18.04 which will serve your files over SSH.
A client system which will connect to the remote server using SSHFS. This system also runs Ubuntu 18.04.
Limited Linux users (non-
root) with the same username should also exist on both systems. If you have not already set up a limited user, review the
How to Secure your Server guide.
The username for this limited user is assumed to be
example_user. Replace all instances of
example_user in this guide with your limited user’s name. As well, the IP address of the remote system is assumed to be
192.0.2.4, so replace all instances of this IP with your remote system’s address.
sshfscan be installed on any Linode distribution, so you can adapt this guide if you are not using Ubuntu.
Log in to your client system and update your packages:
apt-get update && apt-get upgrade
apt-get install sshfs
sshfspackage is available with every Linux package manager. Use the commands specific to your distribution if you are not using Debian or Ubuntu.
Setting Up your Linux Client
In order to mount file systems using SSHFS from a normal user account, you’ll need to add the user to the
fuse group first.
NoteIf you are unfamiliar with users, groups, and file permissions, visit the Users and Groups guide for a brief introduction.
To check if the
fusegroup exists run:
cat /etc/group | grep 'fuse'
If the group exists, execute the following command with
sudo, substituting your user account name in place of
sudo usermod -a -G fuse example_user
If the group does not exist it has to be created and the user added to the
sudo groupadd fuse sudo usermod -a -G fuse example_user
Log out from the client system and log back in to activate the group membership.
Mounting the Remote File System
You can use the command
sshfs to mount a remote filesystem. The syntax for mounting a filesystem with
sshfs [[email protected]]host:[directory] mountpoint [options]
NoteYou can read more about
sshfsin the sshfs manual.
Create a directory as a destination for the mounted folder.
Mount the home directory of the remote system’s user to the new directory on your client system:
sshfs [email protected]:/home/example_user sshfs-dir
List the contents of the mounted directory. You should see the content of the folder that was mounted on the remote system:
ls -al sshfs-dir
To unmount the filesystem, use the
To keep your server’s directory mounted on your system through reboots, create a persistent mount. This is accomplished by updating your system’s
Set Up Key-Based Authentication for SSH
When setting up a mount listed in
/etc/fstab, your client system will not be able to accept a password for the SSH connection. Instead, you can use
public/private keypairs to authenticate with the remote server. This section describes how to create a keypair if you do not already have one.
This command will overwrite an existing RSA key pair, potentially locking you out of other systems.
If you’ve already created a key pair, skip this step. To check for existing keys, run ls ~/.ssh/id_rsa*.
If you accidentally lock yourself out of your Linode, use Lish to update your authorized_keys file and regain SSH access.
Generate a keypair with the
ssh-keygencommand; accept the default values for the options it presents:
ssh-keygen -t rsa
From the client system, copy your new public SSH key to the remote user’s
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
If your system is older, this file may be named
authorized_keys2. Consult your Linode’s
/etc/ssh/sshd_configif you are unsure:
grep authorized_keys /etc/ssh/sshd_config
At this point, you should be able to log into the remote server as
example_userwithout entering a password. Confirm this:
On a new line, add a mount directive to your
/etc/fstabfile which matches the following syntax:
- File: /etc/fstab
[email protected]:/home/example_user /home/example_user/sshfs-dir fuse.sshfs noauto,x-systemd.automount,_netdev,follow_symlinks,identityfile=/home/example_user/.ssh/id_rsa,allow_other,default_permissions,reconnect 0 0
NoteYou will need to use
sudoprivileges to edit this file from your limited user.
Reboot your system. Then, list the contents of the mounted directory. You should see the content of the folder that was mounted on the remote system:
ls -al /home/example_user/sshfs-dir
After completing this guide you will be able to transfer files to a remote server from your client machine without using an FTP client. If you still want to learn how to use an FTP client, check out our guide: Transfer Files with FileZilla.
This page was originally published on