Skip to content

Instantly share code, notes, and snippets.

@Hubbitus
Created February 11, 2017 15:00
Show Gist options
  • Save Hubbitus/c40d986921cbed6a8ad585eee00a7d77 to your computer and use it in GitHub Desktop.
Save Hubbitus/c40d986921cbed6a8ad585eee00a7d77 to your computer and use it in GitHub Desktop.
Afuse sshfs automounter (/usr/sbin/mount.afuse)
#!/bin/bash
# afuse-sshfs mount helper to automatically mount remote machines.
# It is intended to be used as mount.afuse in command line. F.e. in /etc/fstab you may mount directory like:
# afuse# /mnt/remote afuse auto 0 0
# And then as regular user just do:
# $ cd /mnt/remote/user@remote.host/remote/path
# and folder /mnt/remote/user@remote.host will be mounted automatically!
#
# On Mac some also recommend add defer_permissions,noappledouble mount options.
# Mount under user and group which are owners of mount point
su -l $( ls -dl "$2" | cut -d' ' -f3) -c "afuse -o mount_template='sshfs -o reconnect -o auto_cache -o kernel_cache %r:/ %m' -o unmount_template='fusermount -u -z %m' -o auto_unmount '$2'"
@Hubbitus
Copy link
Author

Habrahabr post on Russian about this gist file helper: https://habrahabr.ru/post/321636/

@vonpupp
Copy link

vonpupp commented Mar 4, 2019

@Hubbitus, who should the the owner and group of the /mnt/remote folder? Do you use a group for the users that are able to use afuse? Thanks.

@Hubbitus
Copy link
Author

Hubbitus commented Aug 8, 2021

@vonpupp, user, who will use it. Automount script will automatically get owner user from directory and run mount under he.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment