To share a folder between two Manjaro computers using SSHFS, follow these steps:
- 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
- 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
- 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
- Find the IP address of each computer:
On each computer, run the command ip addr
to find the IP address for the network interface you want to use (usually eth0 or wlan0 for wired or wireless connections respectively). Take note of the IP address of each computer.
- 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.
- 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.
- 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:
- Open the
/etc/fuse.conf
file with a text editor as root. For example, usingnano
:
sudo nano /etc/fuse.conf
- 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
-
Save the changes and close the text editor.
-
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: