Mounting Storage via SSHFS

Prerequisites

  • SSHFS Installation: SSHFS must be installed on your OpenStack VM. If not, you can install it using the package manager of your distribution. For example, on Ubuntu:
sudo apt-get update
sudo apt-get install -y sshfs fuse3
  • SSH keypair: Ensure you have an SSH key pair set up. If not, you can generate one using:
ssh-keygen -t ed25519 -C "user-email@domain.com"

Steps to Mount the Storage

Step 1: Create a Local Mount Point

First, create a directory on your VM where you would like to mount the remote storage.

mkdir -p /home/$USER/sshfs-folder
chown -R $USER:$USER /home/$USER/sshfs-folder

Step 2: Mount the Storage with SSHFS

Use the sshfs command to mount the remote directory (for instance /mnt/data-volume) to your local mount point. Replace YOUR_USERNAME with your instance user, for example for ubuntu images the current user is ubuntu:

mkdir -p /home/$USER/sshfs-folder
chown -R $USER:$USER /home/$USER/sshfs-folder
sshfs -o ssh_command='ssh -i <PRIVATE_SSH_KEY_LOCAL_PATH>' ubuntu@IP_INSTANCE:/mnt/data-volume /home/$USER/sshfs-folder

Remember to set the full path to the private ssh file.

Step 3: Verify the Mount

Check if the storage has been mounted successfully by listing the contents of the /home/$USER/sshfs-folder directory:

ls /home/$USER/sshfs-folder

Step 4: Unmounting the Storage

When done, unmount your storage using the fusermount command:

fusermount -u /home/$USER/sshfs-folder

SHFS mounts are not persistent across reboots by default. For permanence, consider adding the sshfs command to your system's startup scripts or using /etc/fstab.

Alternative mode

You can also use the private key file using the following command:

sshfs -o allow_other,default_permissions,identityfile=<PRIVATE_SSH_KEY_LOCAL_PATH> <USER>@<EXTERNAL_IP>:<REMOTE-PATH> <LOCAL-MOUNT-PATH>

For instance, we can mount a remote folder available in OpenStack instance in path /mnt/data-volume onto the local path /home/$USER/sshfs-folder:

mkdir -p /home/$USER/sshfs-folder
chown -R $USER:$USER /home/$USER/sshfs-folder
sshfs -o allow_other,default_permissions,identityfile=<PRIVATE_SSH_KEY_LOCAL_PATH> ubuntu@EXTERNAL_IP:/mnt/data-volume /home/$USER/sshfs-folder

Remember to set the full path to the private ssh file. If you get an error like this:

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

Uncoment the option user_allow_other in your /etc/fuse.conf.

When done, unmount your storage using the fusermount command:

fusermount -u /home/$USER/sshfs-folder

Other methods to copy files

  • RSYNC: rsync -avz -e "ssh -i <PRIVATE_SSH_KEY_LOCAL_PATH> -p 22" <USER>@<EXTERNAL_IP>:<REMOTE-PATH> <LOCAL-MOUNT-PATH>. Example:
mkdir -p /home/$USER/sshfs-folder
chown -R $USER:$USER /home/$USER/sshfs-folder
rsync -avz -e "ssh -i /home/$USER/id_private_key.pem -p 22" ubuntu@EXTERNAL_IP:/mnt/data-volume/ /home/$USER/sshfs-folder
  • SCP: scp -r -i <PRIVATE_SSH_KEY_LOCAL_PATH> <USER>@<EXTERNAL_IP>:<REMOTE-PATH> <LOCAL-MOUNT-PATH>. Example:
mkdir -p /home/$USER/sshfs-folder
chown -R $USER:$USER /home/$USER/sshfs-folder
scp -r -i /home/$USER/id_private_key.pem ubuntu@EXTERNAL_IP:/mnt/data-volume/ /home/$USER/sshfs-folder
  • SFTP: sftp -P 22 -i <PRIVATE_SSH_KEY_LOCAL_PATH> <USER>@<EXTERNAL_IP>:<REMOTE-PATH>. Example:
sftp -P 22 -i /home/$USER/id_private_key.pem ubuntu@EXTERNAL_IP:/mnt/data-volume
ls
exit