Table of Contents
SFTP Automount
If you would like to automatically mount an sftp share using ssh keys, then this is the guide for you. My use case was attempting to allow access to files on my server to a VM running on that server. That setup requires an internal network to be setup so that the VM can communicate with the host, otherwise this would not work as the default configuration of QEMU/KVM is to not allow communication between guest and host.
Dependencies
sshfs will allow for mounting of remote folders utilizing ssh as the transport medium.
sudo apt install sshfs
SSH Keys
To allow for automatic mounting of sshfs shares without user input, the guest needs to share its' ssh key with the host. This is assuming that the guest has not yet setup an ssh key.
ssh-keygen -t rsa -b 4096
ssh-copy-id <user>@<hostname>
Folder Configuration
The location of the remote share needs a mount point. The mount point needs to have the correct permissions so that it can be mounted at boot and to be able to be read from.
mkdir <mount dir> chown <user>:<group> <mount dir>
fstab Config
A single fstab entry needs to be added with the following format
<remote user>@<remote hostname>:<remote directory> <mount dir> fuse.sshfs defaults 0 0
Mounting the Share
Now reboot the machine and check to make sure everything has mounted as expected.
ls -la <mount dir>