ElementaryOS 0.4: Install davfs2 for WebDAV client

This article will describe installing davfs2 for WebDAV client.

1 Install davfs2

Install davfs2 package.

$ cat <<EOF | sudo debconf-set-selections
davfs2 davfs2/suid_file boolean false
$ sudo apt install -y davfs2

2 Mount WebDAV with davfs2

Mount WebDAV with davfs2 to /mnt directory. Input username and password, and respond to caution of SSL certification.

$ WEBDAV_SERVER_URL=https://webdav-server.hiroom2.com/webdav
$ sudo mount -t davfs ${WEBDAV_SERVER_URL} /mnt
  Username: ${WEBDAV_USERNAME}
  Password: ${WEBDAV_PASSWORD}
Accept certificate for this session? [y,N] y

3 Omit username and password

Writing username and password to /etc/davfs2/secrets will omit inputing username and password.

/etc/davfs2/secrets is the following format.

<URL> <username> <password>

Add URL, username and password to /etc/davfs2/secrets and change permission to 600.

sudo tee -a /etc/davfs2/secrets
$ sudo chmod 600 /etc/davfs2/secrets

4 Accept SSL certification

Accepting SSL certification will omit response to caution of SSL certification.

Get SSL certification of WebDAV server with openssl command and put it to /etc/davfs2/certs.

$ WEBDAV_SERVER_FQDN=webdav-server.hiroom2.com
$ openssl s_client -showcerts -connect ${WEBDAV_SERVER_FQDN}:443 \
          < /dev/null 2> /dev/null | \
   openssl x509 -outform PEM | \
   sudo tee /etc/davfs2/certs/${WEBDAV_SERVER_FQDN}.pem

Add trust_server_cert in /etc/davfs2/davfs2.conf.

$ echo "trust_server_cert ${WEBDAV_SERVER_FQDN}" | \
   sudo tee -a /etc/davfs2/davfs2.conf

5 Mount WebDAV on boot

Add mount entry to /etc/fstab. For avoiding mounting WebDAV before network initialization, you need to add _netdev option. For making x-systemd.automount to mount WebDAV, you need to add x-systemd.automount to option.

$ echo "${WEBDAV_SERVER_URL} /mnt davfs _netdev,x-systemd.automount 0 0" | \
sudo tee -a /etc/fstab