Tutorial: how to automatically mount WebDAV shares at boot in Linux

In Ubuntu (and Kubuntu or Lubuntu) you can quite easily access a WebDav (or WebDavs) share using the standard file manager: Nautilus, Konqueror or PcManFm.

Just put in the address bar the site you want to open (for example: davs://yoursitename or webdav://yoursitename) and click on enter… That’s it (probably you will be asked for credentials – just put the right ones there…)!

To make it work you only need to know if the connection is secure (davs) or not (webdav) and if the package davfs2 is installed (open a terminal and type “sudo apt-get install davfs2”).

However in some cases you may want to have this share always mounted in your system and without the need to put credentials. If this is your case, the solution is pretty easy:

Create a folder on your disk into which the web share will be mounted:
sudo mkdir /mnt/sharename

sudo nano /etc/davfs2/secrets

add the line:
https://www.yourshare.com username password

and now you need to make sure the connection is made each time you start your computer:

sudo nano /etc/fstab

at the end of the file, on a new line type:

https://www.yourshare.com/ /mnt/sharename    davfs   defaults,uid=username,gid=username,_netdev,auto  0       0

Please note the options uid and gid, these are used to tell to the system which user will be able to write to the share (normally is root). In this case “username” is the one you use on your computer.
The option “_netdev” tells to the system to wait for the connections to be up before attempting to mount the share (otherwise it will fail). The mount will happen automatically, as requested by the option “auto”.

Incoming search terms:

  • how to permantantly mount a webdav disk

There are 6 comments left Go To Comment

  1. Pasi /

    Sorry ask… but I needed some advice…

    I have a situation that I’ve done my own owncloud server to ubuntu 14.04 according to these instructions.

    However my main problem is that I need to sync those www/owncloud pictures to the other HDD and I’ve tried that with rsync (cron). With my own username everything is just fine but there is a problems with my wife account because of permission problems (don’t get rsync working as a root-rights).

    So I’ve tried to mount my wife owncloud files with webdav and partially succeed. But what I need is manually login with my wife username & password to my ubuntu so it mounts that directory. (Because from that directory rsync with cron is working).

    Do you know how to automaticly mount (other user) webdav without needed to do anything manually.

  2. Pasi /
    1. Stefano Prenna / Post Author

      Hello Pasi, could describe the actuaL setup? It shouldn’t be a problem to mount automatically the folder with your wife’s credentials, however a better understanding of your configuration would help…

  3. gajus /

    Hi Stefano, thanks for your article. The fstab entry does actually mount my share after boot. the only problem is that creating a folder in the mount results in: operation not permitted. Even when invoking root privileges through sudo.

    This leads me to suspect I’ve either misconfigured webdav which somehow doesnt allow directories to created or that my mount doesnt permit write even though I have explicitly specified rw (instead of the defaults in your example) as an option in fstab.

    I was hoping you could shed some light and perhaps point me in the right direction..

    Regards Gajus!

    1. Stefano Prenna / Post Author

      Without knowing the details of your configuration, I would go step by step:

      1. what’s the exact error message?
      2. has the local folder appropriate rights (before mount)? Check that with ls -l
      3. which permissions are visible once the folder is mounted?

  4. Lecquio /

    I had an error mounting a webdav on boot because it didn’t find the remote address.
    The _netdev parameter save my day
    Thanks a lot!

Leave a Reply

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