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

How to install CSF Firewall on CentOS 7

ConfigServer (CSF) is advanced open-source firewall for Linux. If you are like me, I don’t really care much for the native firewalld that’s included with RHEL7 releases, and I’ve used APF for years which is basically just a frontend for iptables. Here’s instructions on how to install it: 1. Disable firewalld systemctl stop firewalld systemctl […]

Read More

ScreenCloud: Troubleshooting missing Python modules after updates

One of my favorite tools that I find myself using quite often is called “ScreenCloud“. It allows you to quickly select any area of your workspace, create an sized screen shot, and then upload it or export it off to their server, your Dropbox account or an SFTP server. If you’ve recently performed upgrades, either […]

Read More

3 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. ^^

Leave a Reply

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

Twitter: kireguy

Tweeter button Facebook button Myspace button