Automatically mount Nextcloud on user homedir via davfs and autofs

Last year we moved from a traditional Samba based network to a Nextcloud based one. Despite having some more space taken on the local disk we have the advantage of being able to work everywhere, having files backed up immediately (or at least as soon as there’s a network connection) and still being able to limit file access through groups selection.

With the old Samba configuration we had ssh access to the main server where we hold the office ssh key, and from which we start most of our remote sessions. When the file was on the filesystem it was rather easy to adapt permissions to allow unprivileged user to read the key, but now with Nextcloud the files are not accessible anymore (because the storage is encrypted! Otherwise you can access it in Nextcloud data dir).

But we still have the chance to mount Nextcloud via webdav. This is easily achievable by following Nextcloud user manual about mounting from command line.

But in the past, at least with Ubuntu 12.04, davfs mounts weren’t very much stable… Also it’s annoying to remember to mount the share when you need, but most of all remembering to unmount it before logging out (or when your session terminates unexpectedly). So I had the goal to use autofs to mount user’s Nextcloud share automatically, and of course leave them unmounted when not needed. Continua a leggere