[HowTo] Share folders via SSHFS / Compartir carpeta con SSHFS

To share a folder between two Manjaro computers using SSHFS, follow these steps:

Para compartir una carpeta entre dos computadoras Manjaro usando SSHFS, siga estos pasos:

Vea a continuación la versión en Español

  1. Install the SSH server and SSHFS on both computers:

On both computers, open a terminal and run the following command to install the SSH server and SSHFS:

sudo pacman -S openssh sshfs
  1. Start and enable the SSH server:

On the computer that will share the folder (the server), start and enable the SSH server by running the following commands:

sudo systemctl enable --now sshd
  1. Create a folder to share:

On the server, create a folder that you want to share:

sudo mkdir -p /remote/path
sudo chown $USER:$USER /remote/path
  1. Set up SSH key authentication (optional):

To avoid entering a password each time you connect, you can set up SSH key authentication between the two computers. On the client computer, generate an SSH key pair if you don’t have one already:

ssh-keygen

Then, copy the public key to the server:

ssh-copy-id username@server_ip_address

Replace “username” with your username on the server and “server_ip_address” with the server’s IP address.

  1. Mount the shared folder using SSHFS:

On the client computer, create a folder where you want to mount the shared folder:

sudo mkdir -p /local/path
sudo chown $USER:$USER /local/path

Now, mount the shared folder from the server using SSHFS:

sshfs -o IdentityFile=/home/user/.ssh/id_rsa,idmap=user,allow_other,_netdev,follow_symlinks,ServerAliveInterval=15,ServerAliveCountMax=3,reconnect,noatime,auto username@server_ip_address:/remote/path /local/path

Replace “username” with your username on the server, “server_ip_address” with the server’s IP address, and “/remote/path” with the path to the shared folder on the server.

The shared folder from the server should now be accessible on the client computer through the “/local/path” directory.

  1. Unmount the shared folder:

To unmount the shared folder on the client computer, use the following command:

fusermount -u /local/path

Remember that you need an active network connection between the two computers and that the SSH server must be running on the server computer for SSHFS to work.

Additionally, you can add the following command to the fstab file to automatically mount the shared folder at system startup:

username:server_ip_address:/remote/path /local/path fuse.sshfs IdentityFile=/home/user/.ssh/id_rsa,idmap=user,allow_other,_netdev,follow_symlinks,ServerAliveInterval=45,ServerAliveCountMax=2,reconnect,noatime,auto,x-gvfs-show 0 0

Explanation of each option in that command:

  • username:server_ip_address: username and IP address of the server.
  • /remote/path: path of the shared folder on the server.
  • /local/path: mount point on the client computer.
  • fuse.sshfs: file system type.
  • IdentityFile=/home/user/.ssh/id_rsa: path to the SSH private key file.
  • idmap=user: Maps the remote user and group IDs to the local user and group IDs.
  • allow_other: allows access to other users.
  • _netdev: indicates that the file system requires a network connection.
  • follow_symlinks: follows symbolic links in the remote file system.
  • ServerAliveInterval=45: interval in seconds to send a “keep-alive” message to the server.
  • ServerAliveCountMax=2: maximum number of “keep-alive” messages without response before disconnecting.
  • reconnect: attempts to automatically reconnect in case of disconnection.
  • noatime: does not update the access time of the file.
  • auto: automatically mounts the file system at system startup.
  • x-gvfs-show: shows the file system in the file manager (e.g. Nautilus).

Note that you must have an active network connection between the two computers and that the SSH server must be running on the server computer for SSHFS to work.

In case you want to use the allow_other option in your SSHFS command and encounter the following error:

fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf

This means that you need to enable the user_allow_other option in the configuration file /etc/fuse.conf. To do so, follow these steps:

  1. Open the /etc/fuse.conf file with a text editor as root. For example, using nano:
sudo nano /etc/fuse.conf
  1. Look for the line that contains #user_allow_other and uncomment it by removing the # symbol at the beginning of the line. It should look like this:
user_allow_other
  1. Save the changes and close the text editor.

  2. Now, the allow_other option should work properly with your SSHFS command.

The allow_other option allows other users (besides the user who mounts the file system) to access the shared files and directories. Enabling user_allow_other in /etc/fuse.conf allows non-root users to specify the allow_other or allow_root mount options. Note that this can have security implications, as it allows access to shared files by other users on the system. Make sure you understand the security implications before enabling this option.

For more information on SSHFS and its options, refer to these resources:


En Español

Para compartir una carpeta entre dos computadoras Manjaro usando SSHFS, siga estos pasos:

  1. Instale el servidor SSH y SSHFS en ambas computadoras:

En ambas computadoras, abra un terminal y ejecute el siguiente comando para instalar el servidor SSH y SSHFS:

sudo pacman -S openssh sshfs
  1. Inicie y habilite el servidor SSH:

En la computadora que compartirá la carpeta (el servidor), inicie y habilite el servidor SSH ejecutando los siguientes comandos:

sudo systemctl enable --now sshd
  1. Cree una carpeta para compartir:

En el servidor, cree una carpeta que desee compartir:

sudo mkdir -p /remote/path
sudo chown $USER:$USER /remote/path
  1. Configure la autenticación con clave SSH (opcional):

Para evitar ingresar una contraseña cada vez que se conecte, puede configurar la autenticación con clave SSH entre las dos computadoras. En la computadora cliente, genere un par de claves SSH si aún no tiene uno:

ssh-keygen

Luego, copie la clave pública al servidor:

ssh-copy-id username@server_ip_address

Reemplace “username” con su nombre de usuario en el servidor y “server_ip_address” con la dirección IP del servidor.

  1. Monte la carpeta compartida usando SSHFS:

En la computadora cliente, cree una carpeta donde desee montar la carpeta compartida:

sudo mkdir -p /local/path
sudo chown $USER:$USER /local/path

Ahora, monte la carpeta compartida desde el servidor usando SSHFS:

sshfs -o IdentityFile=/home/user/.ssh/id_rsa,idmap=user,allow_other,_netdev,follow_symlinks,ServerAliveInterval=15,ServerAliveCountMax=3,reconnect,noatime,auto username@server_ip_address:/remote/path /local/path

Reemplace “username” con su nombre de usuario en el servidor, “server_ip_address” con la dirección IP del servidor y “/remote/path” con la ruta de la carpeta compartida en el servidor.

La carpeta compartida del servidor ahora debería ser accesible en la computadora cliente a través del directorio “/local/path”.

  1. Desmonte la carpeta compartida:

Cuando haya terminado de usar la carpeta compartida, puede desmontarla en la computadora cliente con el siguiente comando:

fusermount -u /local/path

Recuerde que necesita tener una conexión de red activa entre las dos computadoras y que el servidor SSH debe estar en funcionamiento en la computadora servidor para que SSHFS funcione.

Además, puede agregar el siguiente comando al archivo fstab para montar automáticamente la carpeta compartida al iniciar el sistema:

username:server_ip_address:/remote/path /local/path fuse.sshfs IdentityFile=/home/user/.ssh/id_rsa,idmap=user,allow_other,_netdev,follow_symlinks,ServerAliveInterval=45,ServerAliveCountMax=2,reconnect,noatime,auto,x-gvfs-show 0 0

Explicación de cada opción en ese comando:

  • username:server_ip_address: nombre de usuario y dirección IP del servidor.
  • /remote/path: ruta de la carpeta compartida en el servidor.
  • /local/path: punto de montaje en la computadora cliente.
  • fuse.sshfs: tipo de sistema de archivos.
  • IdentityFile=/home/user/.ssh/id_rsa: ruta al archivo de clave privada SSH.
  • idmap=user: Mapea los ID de usuario y grupo remotos a los ID de usuario y grupo locales.
  • allow_other: permite el acceso a otros usuarios.
  • default_permissions: habilita el uso de permisos predeterminados.
  • _netdev: indica que el sistema de archivos requiere una conexión de red.
  • follow_symlinks: sigue enlaces simbólicos en el sistema de archivos remoto.
  • ServerAliveInterval=45: intervalo en segundos para enviar un mensaje de “keep-alive” al servidor.
  • ServerAliveCountMax=2: número máximo de mensajes de “keep-alive” sin respuesta antes de desconectar.
  • reconnect: intenta reconectar automáticamente en caso de desconexión.
  • noatime: no actualiza el tiempo de acceso al archivo.
  • auto: monta automáticamente el sistema de archivos al iniciar el sistema.
  • x-gvfs-show: muestra el sistema de archivos en el administrador de archivos (por ejemplo, Nautilus).

Tenga en cuenta que debe tener una conexión de red activa entre las dos computadoras y que el servidor SSH debe estar en funcionamiento en la computadora servidor para que SSHFS funcione.

En el caso de que desee utilizar la opción allow_other en su comando SSHFS y encuentre el siguiente error:

fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf

Esto significa que necesita habilitar la opción user_allow_other en el archivo de configuración /etc/fuse.conf. Para hacerlo, siga estos pasos:

  1. Abra el archivo /etc/fuse.conf con un editor de texto como root. Por ejemplo, usando nano:
sudo nano /etc/fuse.conf
  1. Busque la línea que contiene #user_allow_other y descoméntela eliminando el símbolo # al principio de la línea. Debería verse así:
user_allow_other
  1. Guarde los cambios y cierre el editor de texto.

  2. Ahora, la opción allow_other debería funcionar correctamente con su comando SSHFS.

La opción allow_other permite que otros usuarios (además del usuario que monta el sistema de archivos) accedan a los archivos y directorios compartidos. Habilitar user_allow_other en /etc/fuse.conf permite a los usuarios no root especificar las opciones de montaje allow_other o allow_root. Tenga en cuenta que esto puede tener implicaciones de seguridad, ya que permite el acceso a los archivos compartidos por otros usuarios en el sistema. Asegúrese de comprender las implicaciones de seguridad antes de habilitar esta opción.

1 Like