inside the mind of a linux admin

Creating a local ownCloud mount point in Linux using WebDAV

ownCloud is enterprise file sync and share that is self-hosted in your data center, on your servers, using your storage. ownCloud provides Universal File Access through a single front-end to all of your disparate systems. Users can access company files on any device, anytime, from anywhere while IT can manage, control and audit file sharing activity to ensure security and compliance measures are met.

WebDAV (Web Distributed Authoring and Versioning) allows you to “mount” your ownCloud content as a local mount point on your local Linux environment.

I prefer this over using the ownCloud client program, as it gives me much more flexibility with my data (e.g. I can rsync directly from CLI from my local storage to the ownCloud and vice versa – effortlessly).

Here’s how I did it:

NOTE: YOU WILL NOT NEED TO BE ROOT TO USE THE MOUNT, BUT ALL OF THESE COMMANDS ASSUME YOU ARE ROOT.
THESE INSTRUCTIONS ALSO ASSUME YOU HAVE A VALID SSL CERTIFICATE FOR YOUR OWNCLOUD HOST. IF YOU DO NOT, REPLACE HTTPS WITH HTTP IN ALL INSTANCES BELOW.

1. Install davfs2
Using your Linux distribution’s package manager, install the ‘davfs2’ package which is available in most all repositories regardless of Linux flavor.

Ubuntu:

# apt-get install davfs2

Fedora/CentOS/RHEL:

# yum install davfs2

2. Create and set permissions for a local mount point for your ownCloud data.
(I prefer mine in /owncloud — replace all instances of ‘youruser’ with your non-root username)

# mkdir /owncloud
# chown youruser.youruser /owncloud
# mkdir ~youruser/.davfs2
# touch ~youruser/.davfs2/secrets
# chmod 600 ~youruser/.davfs2/secrets
# chown -R youruser.youruser ~youruser/.davfs2/

3. Edit ~youruser/.davfs2/secrets with your favorite editor to store your ownCloud credentials:

https://yourdomain.com/owncloud/remote.php/webdav youruser yourpassword

4. Edit /etc/fstab and put the following entry in to tell the filesystem how to mount it:

https://yourdomain.com/owncloud/remote.php/webdav/ /owncloud davfs user,rw,auto 0 0

Note: if you prefer to not have the mountpoint auto mounted each time you log-in, change auto to noauto

5. Add youruser to the ‘davfs2’ group so it can use it.

# usermod -aG davfs2 youruser

Note: you will need to log out and back in to get your new group to take effect

6. Now all you need to do is mount your ownCloud webdav instance

# mount /owncloud

Problems?

On some operating systems, the mount.davfs binary does not have setuid privileges to run as a non-root user. If you see an error such as:

/sbin/mount.davfs: program is not setuid root

You are running an OS that needs the privileges granted. To do so, run this as root:

# chmod +s /usr/sbin/mount.davfs


Want faster rsyncs??

If you’re transferring a large amount of files with rsync, you’ll want to pass it some extra arguments.

Check the rsync man page for:

  • –size-only because most webdav implementations do not accept setting modification time
  • –no-whole-file to tell rsync its handling a remote filesystem
  • –inplace having rsync replacing files directly, instead of uploading an then replacing



Enjoy!

Related Posts

synergy: How to enable crypto (encryption) and generate SSL certificate

The newer Linux versions of the popular mouse/keyboard sharing application “synergy” now has built in encryption. Here’s how to configure it: Just simply passing the –enable-crypto flag on your synergy server without having a proper SSL certificate will result in the inability to connect to clients and generate an error message similar to this in […]

Read More

Change Number Pad Delete (dot) key from a comma in Ubuntu Linux

I recently purchased a new keyboard and updated to the latest Ubuntu, I’m also an avid user of the number pad for quick input when dealing with spreadsheets or accounting. I found that my num pad’s delete key (“.”) was outputting a comma (“,”) instead. Pretty annoying? I agree, but this can be very easily […]

Read More

4 Comments

  • Mathieu on Sunday, March 15, 2015

    Hello,

    That’s interesting, unfortunately it’s not very reliable at the moment.
    I noticed two problems in particular.

    The first is it can be very slow. You cannot use it with unison so basically you cannot use it in any smart way get different copies up to date. http://savannah.nongnu.org/support/?108539 describes the problem and shows that it’s unlikely to change any time soon (partly due to file managers, partly due to the fact it’s monothread)

    The second is even more annoying. After one reboot, I had set the relevant line in /etc/fstab in auto mode but did not configure davfs2 to actually select the proper user to mount the partition. It locks the boot process waiting for the partition to be mounted. Overly hardcore problem.

    I found that doing apt-get install owncloud-client is much more efficient in the end than any attempt to script and automate the update process otherwise.

  • Miguel on Saturday, February 13, 2016

    I prefer this over FTPfs because unlike owncloud-client, it takes no space on the disk.

  • Omer on Thursday, March 3, 2016

    Matthieu,

    Along with yourfolder/.davfs/secrets ensure that you have the same line at /etc/davfs2/secrets file as well. In my case didn’t ask for passwords after that. Though I must admit, I’m still a bit hesitant to reboot. ^^

  • Jott on Monday, December 17, 2018

    Hi,
    unfortunately there seems to be no group named davfs2 on my system, which is arch.
    Also System won’t boot anymore with that entry in fstab. I needed to remove that in order to get my system booting again.

    I am too less admin to know, how to solve that on my own 😀

    Nontheless, thanks for your work and explanation!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.