Autofs: mounting the Hetzner Storage Box automatically
Requirements
Besides having a Linux server and a Hetzner Storage Box, you will need to set up SSH keys for the storage box.
This tutorial is based on Debian/Ubuntu. It works the same on SUSE or RedHat based distros, though the package names could differ.
Install packages
sudo apt install fuse3 sshfs autofs
Prepare folders
sudo /mnt/hetzner/
Setup ssh key to box storage
cat ~/.ssh/id_ed25519.pub | ssh -p23 [email protected] install-ssh-key
Setup autofs
sudo nano /etc/auto.master
Adding this:
/mnt/hetzner /etc/auto.hetzner --timeout=60 --ghost
sudo nano /etc/auto.hetzner
Adding this and adapt:
backup-storage -fstype=fuse,rw,allow_other,IdentityFile=/root/.ssh/hetzner_backup,StrictHostKeyChecking=no,ServerAliveInterval=15,ServerAliveCountMax=3,reconnect,uid=0,gid=0,umask=022 :sshfs\#[email protected]\:/
Stating and enabling autofs
sudo systemctl enable autofs
sudo systemctl start autofs
sudo systemctl status autofs
sudo systemctl restart autofs
Testing
sudo ls -lah /mnt/hetzner
mkdir -p /mnt/hetzner/backup-storage/test
sudo ls -lah /mnt/hetzner/backup-storage/