AlpineLinux 3.6: Install davfs2 for WebDAV client

This article will describe installing davfs2 for WebDAV client.

1 Install davfs2

Install davfs2 package.

$ sudo sed -e 's;^#http\(.*\)/v3.6/community;http\1/v3.6/community;g' \
       -i /etc/apk/repositories
$ sudo apk update
$ sudo apk add davfs2

2 Get SSL certification

You need to get SSL certification for https.

$ WEBDAV_SERVER_FQDN=webdav-server.hiroom2.com
$ sudo apk add openssl
$ 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
$ echo "trust_server_cert ${WEBDAV_SERVER_FQDN}.pem" | \
    sudo tee -a /etc/davfs2/davfs2.conf

3 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_FQDN}/uploads
$ sudo mount -t davfs ${WEBDAV_SERVER_URL} /mnt
Please enter the username to authenticate with server
https://webdav-server.hiroom2.com/uploads or hit enter for none.
admin
  Username: Please enter the password to authenticate user admin with server
https://webdav-server.hiroom2.com/uploads or hit enter for none.
  Password:

4 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.

$ WEBDAV_USERNAME=admin
$ WEBDAV_PASSWORD=webdav
$ echo "${WEBDAV_SERVER_URL} ${WEBDAV_USERNAME} ${WEBDAV_PASSWORD}" | \
sudo tee -a /etc/davfs2/secrets
$ sudo chmod 600 /etc/davfs2/secrets

5 Mount WebDAV on boot

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

$ sudo rc-update add netmount
$ echo "${WEBDAV_SERVER_URL} /mnt davfs _netdev 0 0" | \
    sudo tee -a /etc/fstab